Sha256: 4ade7034c9e77e5b259be12f873c794f55cfcad866a932fa5fd844be13e87040

Contents?: true

Size: 1.25 KB

Versions: 13

Compression:

Stored size: 1.25 KB

Contents

module WWW
  class Mechanize
    class Form
      # 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 SelectList < MultiSelectList
        def initialize(name, node)
          super(name, node)
          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)
          if new != new.to_s and new.respond_to? :first
            super([new.first])
          else
            super([new.to_s])
          end
        end

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

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
mechanize-ntlm-0.9.1 lib/www/mechanize/form/select_list.rb
mechanize-0.7.7 lib/www/mechanize/form/select_list.rb
mechanize-0.7.6 lib/www/mechanize/form/select_list.rb
mechanize-0.7.8 lib/www/mechanize/form/select_list.rb
mechanize-0.8.0 lib/www/mechanize/form/select_list.rb
mechanize-0.8.4 lib/www/mechanize/form/select_list.rb
mechanize-0.8.1 lib/www/mechanize/form/select_list.rb
mechanize-0.8.3 lib/www/mechanize/form/select_list.rb
mechanize-0.8.2 lib/www/mechanize/form/select_list.rb
mechanize-0.8.5 lib/www/mechanize/form/select_list.rb
mechanize-0.9.1 lib/www/mechanize/form/select_list.rb
mechanize-0.9.2 lib/www/mechanize/form/select_list.rb
mechanize-0.9.0 lib/www/mechanize/form/select_list.rb