Class: Mechanize::Form::Option
- Inherits:
-
Object
- Object
- Mechanize::Form::Option
- Defined in:
- lib/mechanize/form/option.rb
Overview
This class contains an option found within SelectList. A SelectList can have many Option classes associated with it. An option can be selected by calling Option#tick, or Option#click.
To select the first option in a list:
select_list.first.tick
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#select_list ⇒ Object
readonly
Returns the value of attribute select_list.
-
#selected ⇒ Object
(also: #selected?)
readonly
Returns the value of attribute selected.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#value ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#click ⇒ Object
Toggle the selection value of this option.
-
#initialize(node, select_list) ⇒ Option
constructor
A new instance of Option.
-
#select ⇒ Object
(also: #tick)
Select this option.
-
#unselect ⇒ Object
(also: #untick)
Unselect this option.
Constructor Details
#initialize(node, select_list) ⇒ Option
Returns a new instance of Option.
17 18 19 20 21 22 23 |
# File 'lib/mechanize/form/option.rb', line 17 def initialize(node, select_list) @node = node @text = node.inner_text @value = Mechanize::Util.html_unescape(node['value'] || node.inner_text) @selected = node.has_attribute? 'selected' @select_list = select_list # The select list this option belongs to end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
12 13 14 |
# File 'lib/mechanize/form/option.rb', line 12 def node @node end |
#select_list ⇒ Object (readonly)
Returns the value of attribute select_list.
12 13 14 |
# File 'lib/mechanize/form/option.rb', line 12 def select_list @select_list end |
#selected ⇒ Object (readonly) Also known as: selected?
Returns the value of attribute selected.
12 13 14 |
# File 'lib/mechanize/form/option.rb', line 12 def selected @selected end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
12 13 14 |
# File 'lib/mechanize/form/option.rb', line 12 def text @text end |
#value ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute value.
12 13 14 |
# File 'lib/mechanize/form/option.rb', line 12 def value @value end |
Instance Method Details
#click ⇒ Object
Toggle the selection value of this option
40 41 42 43 |
# File 'lib/mechanize/form/option.rb', line 40 def click unselect_peers @selected = !@selected end |
#select ⇒ Object Also known as: tick
Select this option
26 27 28 29 |
# File 'lib/mechanize/form/option.rb', line 26 def select unselect_peers @selected = true end |
#unselect ⇒ Object Also known as: untick
Unselect this option
32 33 34 |
# File 'lib/mechanize/form/option.rb', line 32 def unselect @selected = false end |