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

#name, #node, #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.



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

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.



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

def checked
  @checked
end

#formObject (readonly)

Returns the value of attribute form.



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

def form
  @form
end

Instance Method Details

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

:nodoc:



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

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

#[](key) ⇒ Object



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

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

#checkObject



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

def check
  uncheck_peers
  @checked = true
end

#clickObject



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

def click
  checked ? uncheck : check
end

#hashObject

:nodoc:



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

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

#labelObject



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

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

#pretty_print_instance_variablesObject

:nodoc:



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

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

#textObject



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

def text
  label.text rescue nil
end

#uncheckObject



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

def uncheck
  @checked = false
end