File: select_list.rb

package info (click to toggle)
ruby-mechanize 2.7.6-1%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,480 kB
  • sloc: ruby: 11,380; makefile: 5; sh: 4
file content (44 lines) | stat: -rw-r--r-- 1,057 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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
class Mechanize::Form::SelectList < Mechanize::Form::MultiSelectList

  def initialize node
    super
    if selected_options.length > 1
      selected_options.reverse[1..selected_options.length].each do |o|
        o.unselect
      end
    end
  end

  def value
    value = super
    if value.length > 0
      value.last
    elsif @options.length > 0
      @options.first.value
    else
      nil
    end
  end

  def value=(new_value)
    if new_value != new_value.to_s and new_value.respond_to? :first
      super([new_value.first])
    else
      super([new_value.to_s])
    end
  end

  def query_value
    value ? [[name, value]] : nil
  end

end