Class: WWW::Mechanize::Form::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/www/mechanize/form/option.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, select_list) ⇒ Option

Returns a new instance of Option.



15
16
17
18
19
20
# File 'lib/www/mechanize/form/option.rb', line 15

def initialize(node, select_list)
  @text     = node.inner_text
  @value    = 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

#select_listObject (readonly)

Returns the value of attribute select_list.



10
11
12
# File 'lib/www/mechanize/form/option.rb', line 10

def select_list
  @select_list
end

#selectedObject (readonly) Also known as: selected?

Returns the value of attribute selected.



10
11
12
# File 'lib/www/mechanize/form/option.rb', line 10

def selected
  @selected
end

#textObject (readonly)

Returns the value of attribute text.



10
11
12
# File 'lib/www/mechanize/form/option.rb', line 10

def text
  @text
end

#valueObject (readonly) Also known as: to_s

Returns the value of attribute value.



10
11
12
# File 'lib/www/mechanize/form/option.rb', line 10

def value
  @value
end

Instance Method Details

#clickObject

Toggle the selection value of this option



37
38
39
40
# File 'lib/www/mechanize/form/option.rb', line 37

def click
  unselect_peers
  @selected = !@selected
end

#selectObject Also known as: tick

Select this option



23
24
25
26
# File 'lib/www/mechanize/form/option.rb', line 23

def select
  unselect_peers
  @selected = true
end

#unselectObject Also known as: untick

Unselect this option



29
30
31
# File 'lib/www/mechanize/form/option.rb', line 29

def unselect
  @selected = false
end