| Class | WWW::Mechanize::Option |
| In: |
lib/mechanize/form_elements.rb
|
| Parent: | Object |
This class contains option 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. For example, select the first option in a list:
select_list.first.tick
| value | -> | to_s |
| selected | -> | selected? |
| select_list | [R] | |
| selected | [R] | |
| text | [R] | |
| value | [R] |
# File lib/mechanize/form_elements.rb, line 219
219: def initialize(node, select_list)
220: @text = node.inner_text
221: @value = Util.html_unescape(node['value'])
222: @selected = node.has_attribute? 'selected'
223: @select_list = select_list # The select list this option belongs to
224: end
Toggle the selection value of this option
# File lib/mechanize/form_elements.rb, line 241
241: def click
242: unselect_peers
243: @selected = !@selected
244: end
Select this option
# File lib/mechanize/form_elements.rb, line 227
227: def select
228: unselect_peers
229: @selected = true
230: end
Unselect this option
# File lib/mechanize/form_elements.rb, line 233
233: def unselect
234: @selected = false
235: end