From 1e7ebdd35419421a2f908420fe78eb78ffdfe84b Mon Sep 17 00:00:00 2001 From: Kanezoh Date: Fri, 11 Jun 2021 09:18:29 +0900 Subject: [PATCH] refactor form#initialize --- src/mechanize/form.cr | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/mechanize/form.cr b/src/mechanize/form.cr index 439b021..5b7045f 100644 --- a/src/mechanize/form.cr +++ b/src/mechanize/form.cr @@ -9,18 +9,17 @@ class MechanizeCr::Form property action : String def initialize(node : Node | Myhtml::Node) - @enctype = node["enctype"]? ? node["enctype"] : "application/x-www-form-urlencoded" + @enctype = node.fetch("enctype", "application/x-www-form-urlencoded") @node = node - @fields = Array(MechanizeCr::FormContent::Field).new - @checkboxes = Array(MechanizeCr::FormContent::CheckBox).new - #@action = Mechanize::Util.html_unescape(node['action']) - @action = node["action"] - @method = (node["method"] || "GET").upcase + @fields = Array(MechanizeCr::FormContent::Field).new + @checkboxes = Array(MechanizeCr::FormContent::CheckBox).new + @action = node.fetch("action", "") + @method = node.fetch("method", "GET").upcase #@name = node['name'] #@clicked_buttons = [] #@page = page #@mech = mech -# + #@encoding = node['accept-charset'] || (page && page.encoding) || nil #@ignore_encoding_error = false parse