Sha256: e84f7b86ceb6cf05a466534bdda3586dfb8049a74ab4dd56e508694c3400bf34

Contents?: true

Size: 1.06 KB

Versions: 17

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true
# 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

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
mechanize-2.14.0 lib/mechanize/form/select_list.rb
mechanize-2.13.0 lib/mechanize/form/select_list.rb
mechanize-2.12.2 lib/mechanize/form/select_list.rb
mechanize-2.12.1 lib/mechanize/form/select_list.rb
mechanize-2.12.0 lib/mechanize/form/select_list.rb
mechanize-2.11.0 lib/mechanize/form/select_list.rb
mechanize-2.10.1 lib/mechanize/form/select_list.rb
mechanize-2.10.0 lib/mechanize/form/select_list.rb
mechanize-2.9.2 lib/mechanize/form/select_list.rb
mechanize-2.9.1 lib/mechanize/form/select_list.rb
mechanize-2.9.0 lib/mechanize/form/select_list.rb
mechanize-2.8.5 lib/mechanize/form/select_list.rb
mechanize-2.8.4 lib/mechanize/form/select_list.rb
mechanize-2.8.3 lib/mechanize/form/select_list.rb
mechanize-2.8.2 lib/mechanize/form/select_list.rb
mechanize-2.8.1 lib/mechanize/form/select_list.rb
mechanize-2.8.0 lib/mechanize/form/select_list.rb