add checkbox comment

master
Kanezoh 2021-11-18 11:13:30 +09:00
parent fca04b29b9
commit 794a2085de
7 changed files with 17 additions and 3 deletions

View File

@ -9,7 +9,7 @@ class Mechanize
# returns http status code
getter code : Int32
# returns page uri
getter uri : URI
getter uri : URI
def initialize(uri : URI, response : ::HTTP::Client::Response, body : String, code : Int32)
@uri = uri

View File

@ -1,4 +1,6 @@
# This class represents <input type="checkbox">
class Mechanize::FormContent::CheckBox < Mechanize::FormContent::RadioButton
# set checkbox checked
def check
@checked = true
end

View File

@ -1,6 +1,5 @@
# This class represents <input> elements in the form.
class Mechanize::FormContent::Field
# returns field's 'value' attribute
property value : String?
# returns field's 'name' attribute

View File

@ -1,5 +1,6 @@
require "./option"
# This class represents <select multiple>
class Mechanize::FormContent::MultiSelectList
getter node : Lexbor::Node
getter name : String
@ -18,32 +19,37 @@ class Mechanize::FormContent::MultiSelectList
}
end
# set all options unchecked
def select_none
@values = Array(String).new
options.each &.unselect
end
# set all options checked
def select_all
@values = Array(String).new
options.each &.select
end
# returns all checked options
def selected_options
options.select &.selected?
end
# add new values to options
def values=(new_values)
select_none
new_values.each do |value|
option = options.find { |o| o.value == value }
if option.nil?
@value.push(value)
@values.push(value)
else
option.select
end
end
end
# return all option's values.
def values
@values + selected_options.map &.value
end

View File

@ -30,6 +30,7 @@ class Mechanize::FormContent::Option
@selected = !@selected
end
# returns option checked or not
def selected?
@selected
end

View File

@ -1,3 +1,4 @@
# This class represents <input type="radio">
class Mechanize::FormContent::RadioButton < Mechanize::FormContent::Field
property :checked, :form
@ -7,19 +8,23 @@ class Mechanize::FormContent::RadioButton < Mechanize::FormContent::Field
super(node)
end
# set radiobutton checked
def check
uncheck_peers
@checked = true
end
# set radiobutton checked
def uncheck
@checked = false
end
# change radiobutton state checked or unchecked
def click
checked ? uncheck : check
end
# returns radiobutton checked or not
def checked?
checked
end

View File

@ -1,5 +1,6 @@
require "./multi_select_list"
# This class represents <select> which is not multiple
class Mechanize::FormContent::SelectList < Mechanize::FormContent::MultiSelectList
def initialize(node)
super node