Sha256: 991fb46d72c056ae61819380554f2cd75b6eb0ecc240ef194dda424fb253305b

Contents?: true

Size: 1.26 KB

Versions: 11

Compression:

Stored size: 1.26 KB

Contents

class Mechanize
  class Form
    # This class contains option 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.  For example,
    # select the first option in a list:
    #  select_list.first.tick
    class 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    = 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
        if @select_list.instance_of? SelectList
          @select_list.select_none
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 6 rubygems

Version Path
kitamomonga-mechanize-0.9.3.20090724215219 lib/mechanize/form/option.rb
tenderlove-mechanize-0.9.3.20090911221705 lib/mechanize/form/option.rb
domo-0.0.4 vendor/bundle/ruby/1.9.1/gems/mechanize-1.0.0/lib/mechanize/form/option.rb
aai10-mechanize-2.0.1.0 lib/mechanize/form/option.rb
neocoin-mechanize-2.0.2 lib/mechanize/form/option.rb
mechanize-2.0.1 lib/mechanize/form/option.rb
mechanize-2.0 lib/mechanize/form/option.rb
mechanize-2.0.pre.2 lib/mechanize/form/option.rb
mechanize-2.0.pre.1 lib/mechanize/form/option.rb
mechanize-1.0.1.beta.20110107104205 lib/mechanize/form/option.rb
mechanize-1.0.0 lib/mechanize/form/option.rb