Sha256: 08aa489819cb036e550e22e6e928d0942fc73e51333c47fcac0d5513d93973c6

Contents?: true

Size: 1.1 KB

Versions: 25

Compression:

Stored size: 1.1 KB

Contents

##
# This class contains an option found within SelectList.  A SelectList can
# have many Option classes associated with it.  An option can be selected by
# calling Option#tick, or Option#click.
#
# To select the first option in a list:
#
#   select_list.first.tick

class Mechanize::Form::Option
  attr_reader :value, :selected, :text, :select_list

  alias :to_s :value
  alias :selected? :selected

  def initialize(node, select_list)
    @text     = node.inner_text
    @value    = Mechanize::Util.html_unescape(node['value'] || node.inner_text)
    @selected = node.has_attribute? 'selected'
    @select_list = select_list # The select list this option belongs to
  end

  # Select this option
  def select
    unselect_peers
    @selected = true
  end

  # Unselect this option
  def unselect
    @selected = false
  end

  alias :tick   :select
  alias :untick :unselect

  # Toggle the selection value of this option
  def click
    unselect_peers
    @selected = !@selected
  end

  private
  def unselect_peers
    return unless Mechanize::Form::SelectList === @select_list

    @select_list.select_none
  end
end

Version data entries

25 entries across 25 versions & 4 rubygems

Version Path
mechanize-2.7.5 lib/mechanize/form/option.rb
mechanize-2.7.4 lib/mechanize/form/option.rb
mechanize-2.7.3 lib/mechanize/form/option.rb
mechanize-2.7.2 lib/mechanize/form/option.rb
mechanize-2.7.1 lib/mechanize/form/option.rb
mechanize-2.7.0 lib/mechanize/form/option.rb
mechanize-2.6.0 lib/mechanize/form/option.rb
mechanize-2.5.1 lib/mechanize/form/option.rb
mechanize-2.5 lib/mechanize/form/option.rb
mechanize-2.4 lib/mechanize/form/option.rb
frameworks-capybara-0.2.0.rc6 vendor/bundle/ruby/1.8/gems/mechanize-2.3/lib/mechanize/form/option.rb
frameworks-capybara-0.2.0.rc5 vendor/bundle/ruby/1.8/gems/mechanize-2.3/lib/mechanize/form/option.rb
frameworks-capybara-0.2.0.rc4 vendor/bundle/ruby/1.8/gems/mechanize-2.3/lib/mechanize/form/option.rb
frameworks-capybara-0.2.0.rc3 vendor/bundle/ruby/1.8/gems/mechanize-2.3/lib/mechanize/form/option.rb
frameworks-capybara-0.2.0.rc2 vendor/bundle/ruby/1.8/gems/mechanize-2.3/lib/mechanize/form/option.rb
mechanize-2.3 lib/mechanize/form/option.rb
mechanize-2.2.1 lib/mechanize/form/option.rb
mechanize-2.2 lib/mechanize/form/option.rb
mechanize-2.1.1 lib/mechanize/form/option.rb
domo-0.0.5 vendor/bundle/ruby/1.9.1/gems/mechanize-2.1/lib/mechanize/form/option.rb