From 16e4c7aed37aaa25a5690398cf4bd8b81aa6b8a7 Mon Sep 17 00:00:00 2001 From: Kanezoh Date: Wed, 19 May 2021 21:23:52 +0900 Subject: [PATCH] model node --- src/mechanize.cr | 4 +++- src/mechanize/form/check_box.cr | 2 +- src/mechanize/form/field.cr | 10 +++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/mechanize.cr b/src/mechanize.cr index 315826d..a2d2b66 100644 --- a/src/mechanize.cr +++ b/src/mechanize.cr @@ -25,7 +25,9 @@ class Mechanize form = MechanizeCr::Form.new(node) query.each do |k,v| - form.fields << MechanizeCr::FormContent::Field.new({"name" => k}, v) + node = Node.new + node["name"] = k + form.fields << MechanizeCr::FormContent::Field.new(node, v) end #post_form(uri, form, headers) end diff --git a/src/mechanize/form/check_box.cr b/src/mechanize/form/check_box.cr index 0412978..e7fbb77 100644 --- a/src/mechanize/form/check_box.cr +++ b/src/mechanize/form/check_box.cr @@ -2,7 +2,7 @@ class MechanizeCr::FormContent::CheckBox < MechanizeCr::FormContent::Field property :checked property :form - def initialize(node : Node, value : String = node["value"]) + def initialize(node : Node, value : String = node.fetch("value", "")) @checked = !!node["checked"] @form = form super(node) diff --git a/src/mechanize/form/field.cr b/src/mechanize/form/field.cr index 8e69f17..7615ac2 100644 --- a/src/mechanize/form/field.cr +++ b/src/mechanize/form/field.cr @@ -1,10 +1,14 @@ class MechanizeCr::FormContent::Field - property :node, :value - def initialize(node : Hash(String, String), value : String = node["value"]) + property :node, :value, :name + def initialize(node : Node, value : String = node.fetch("value", ""), name : String = node.fetch("name", "")) @node = node - #@name = Mechanize::Util.html_unescape(node['name']) + @name = name #@raw_value = value @value = value #@type = node['type'] end + + def query_value + [[@name, @value || ""]] + end end