Class: Mechanize::Form::RadioButton

Inherits:
Field
  • Object
show all
Defined in:
lib/mechanize/form/radio_button.rb

Overview

This class represents a radio button found in a Form. To activate the RadioButton in the Form, set the checked method to true.

Direct Known Subclasses

CheckBox

Instance Attribute Summary collapse

Attributes inherited from Field

#index, #name, #node, #raw_value, #type, #value

Instance Method Summary collapse

Methods inherited from Field

#<=>, #dom_class, #dom_id, #inspect, #query_value

Constructor Details

#initialize(node, form) ⇒ RadioButton

Returns a new instance of RadioButton.



10
11
12
13
14
# File 'lib/mechanize/form/radio_button.rb', line 10

def initialize node, form
  @checked = !!node['checked']
  @form    = form
  super(node)
end

Instance Attribute Details

#checkedObject Also known as: checked?

Returns the value of attribute checked.



7
8
9
# File 'lib/mechanize/form/radio_button.rb', line 7

def checked
  @checked
end

#formObject (readonly)

Returns the value of attribute form.



8
9
10
# File 'lib/mechanize/form/radio_button.rb', line 8

def form
  @form
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

:nodoc:



16
17
18
19
20
21
# File 'lib/mechanize/form/radio_button.rb', line 16

def == other # :nodoc:
  self.class === other and
    other.form  == @form and
    other.name  == @name and
    other.value == @value
end

#[](key) ⇒ Object



52
53
54
# File 'lib/mechanize/form/radio_button.rb', line 52

def [](key)
  @node[key]
end

#checkObject



25
26
27
28
# File 'lib/mechanize/form/radio_button.rb', line 25

def check
  uncheck_peers
  @checked = true
end

#clickObject



36
37
38
# File 'lib/mechanize/form/radio_button.rb', line 36

def click
  checked ? uncheck : check
end

#hashObject

:nodoc:



40
41
42
# File 'lib/mechanize/form/radio_button.rb', line 40

def hash # :nodoc:
  @form.hash ^ @name.hash ^ @value.hash
end

#labelObject



44
45
46
# File 'lib/mechanize/form/radio_button.rb', line 44

def label
  (id = self['id']) && @form.page.labels_hash[id] || nil
end

#pretty_print_instance_variablesObject

:nodoc:



56
57
58
# File 'lib/mechanize/form/radio_button.rb', line 56

def pretty_print_instance_variables # :nodoc:
  [:@checked, :@name, :@value]
end

#textObject



48
49
50
# File 'lib/mechanize/form/radio_button.rb', line 48

def text
  label.text rescue nil
end

#uncheckObject



32
33
34
# File 'lib/mechanize/form/radio_button.rb', line 32

def uncheck
  @checked = false
end