Sha256: 7af0792a54a9de1977b8f99fd115268d1d1b3d45f6540a70d7adad89eee80d9e

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

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]] : nil
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
kitamomonga-mechanize-0.9.3.20090724215219 lib/mechanize/form/select_list.rb
tenderlove-mechanize-0.9.3.20090911221705 lib/mechanize/form/select_list.rb