Mechanize::Form::SelectList

This class represents a select list or drop down box in a Form. Set the value for the list by calling SelectList#value=. SelectList contains a list of Option that were found. After finding the correct option, set the select lists value to the option value:

selectlist.value = selectlist.options.first.value

Options can also be selected by "clicking" or selecting them. See Option

Public Class Methods

new(node) click to toggle source
# File lib/mechanize/form/select_list.rb, line 10
def initialize node
  super
  if selected_options.length > 1
    selected_options.reverse[1..selected_options.length].each do |o|
      o.unselect
    end
  end
end

Public Instance Methods

option_with(criteria) 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/select_list.rb, line 38
def option_with criteria
  f = options_with(criteria).first
    yield f if block_given?
  f
end
options_with(criteria) 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/select_list.rb, line 25
def options_with criteria
  criteria = {:name => criteria} if String === criteria
  f = @options.find_all do |thing|
    criteria.all? { |k,v| v === thing.send(k) }
  end
  yield f if block_given?
  f
end
query_value() click to toggle source
# File lib/mechanize/form/select_list.rb, line 63
def query_value
  value ? [[name, value]] : nil
end
value() click to toggle source
# File lib/mechanize/form/select_list.rb, line 44
def value
  value = super
  if value.length > 0
    value.last
  elsif @options.length > 0
    @options.first.value
  else
    nil
  end
end
value=(new) click to toggle source
# File lib/mechanize/form/select_list.rb, line 55
def value=(new)
  if new != new.to_s and new.respond_to? :first
    super([new.first])
  else
    super([new.to_s])
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.