Mechanize::Form::MultiSelectList

This class represents a select list where multiple values can be selected. MultiSelectList#value= accepts an array, and those values are used as values for the select list. For example, to select multiple values, simply do this:

  list.value = ['one', 'two']

Single values are still supported, so these two are the same:

  list.value = ['one']
  list.value = 'one'

Attributes

options[RW]

Public Class Methods

new(node) click to toggle source
    # File lib/mechanize/form/multi_select_list.rb, line 20
20:   def initialize node
21:     value = []
22:     @options = []
23: 
24:     # parse
25:     node.search('option').each do |n|
26:       @options << Mechanize::Form::Option.new(n, self)
27:     end
28: 
29:     super node, value
30:   end

Public Instance Methods

option_with click to toggle source

Find one option on this select list with criteria

Example:

  select_list.option_with(:value => '1').value = 'foo'
    # File lib/mechanize/form/multi_select_list.rb, line 41
41:   
options_with click to toggle source

Find all options on this select list with criteria

Example:

  select_list.options_with(:value => /1|2/).each do |field|
    field.value = '20'
  end
    # File lib/mechanize/form/multi_select_list.rb, line 52
52:   elements_with :option
query_value() click to toggle source
    # File lib/mechanize/form/multi_select_list.rb, line 54
54:   def query_value
55:     value ? value.map { |v| [name, v] } : ''
56:   end
select_all() click to toggle source

Select all options

    # File lib/mechanize/form/multi_select_list.rb, line 65
65:   def select_all
66:     @value = []
67:     options.each { |o| o.tick }
68:   end
select_none() click to toggle source

Select no options

    # File lib/mechanize/form/multi_select_list.rb, line 59
59:   def select_none
60:     @value = []
61:     options.each { |o| o.untick }
62:   end
selected_options() click to toggle source

Get a list of all selected options

    # File lib/mechanize/form/multi_select_list.rb, line 71
71:   def selected_options
72:     @options.find_all { |o| o.selected? }
73:   end
value() click to toggle source
    # File lib/mechanize/form/multi_select_list.rb, line 87
87:   def value
88:     value = []
89:     value.concat @value
90:     value.concat selected_options.map { |o| o.value }
91:     value
92:   end
value=(values) click to toggle source
    # File lib/mechanize/form/multi_select_list.rb, line 75
75:   def value=(values)
76:     select_none
77:     [values].flatten.each do |value|
78:       option = options.find { |o| o.value == value }
79:       if option.nil?
80:         @value.push(value)
81:       else
82:         option.select
83:       end
84:     end
85:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.