Class: Mechanize::Form::Field
- Inherits:
-
Object
- Object
- Mechanize::Form::Field
- Defined in:
- lib/mechanize/form/field.rb
Overview
This class represents a field in a form. It handles the following input tags found in a form:
-
text
-
password
-
hidden
-
int
-
textarea
-
keygen
To set the value of a field, just use the value method:
field.value = "foo"
Direct Known Subclasses
Button, FileUpload, Hidden, Keygen, MultiSelectList, RadioButton, Text, Textarea
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#node ⇒ Object
Returns the value of attribute node.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#dom_class ⇒ Object
This method is a shortcut to get field’s DOM id.
-
#dom_id ⇒ Object
This method is a shortcut to get field’s DOM id.
-
#initialize(node, value = node['value']) ⇒ Field
constructor
A new instance of Field.
- #query_value ⇒ Object
Constructor Details
#initialize(node, value = node['value']) ⇒ Field
Returns a new instance of Field.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mechanize/form/field.rb', line 19 def initialize node, value = node['value'] @node = node @name = Mechanize::Util.html_unescape(node['name']) @value = if value.is_a? String Mechanize::Util.html_unescape(value) else value end @type = node['type'] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
17 18 19 |
# File 'lib/mechanize/form/field.rb', line 17 def name @name end |
#node ⇒ Object
Returns the value of attribute node.
17 18 19 |
# File 'lib/mechanize/form/field.rb', line 17 def node @node end |
#type ⇒ Object
Returns the value of attribute type.
17 18 19 |
# File 'lib/mechanize/form/field.rb', line 17 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
17 18 19 |
# File 'lib/mechanize/form/field.rb', line 17 def value @value end |
Instance Method Details
#<=>(other) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/mechanize/form/field.rb', line 35 def <=> other return 0 if self == other return 1 if Hash === node return -1 if Hash === other.node node <=> other.node end |
#dom_class ⇒ Object
This method is a shortcut to get field’s DOM id. Common usage: form.field_with(:dom_class => “foo”)
50 51 52 |
# File 'lib/mechanize/form/field.rb', line 50 def dom_class node['class'] end |
#dom_id ⇒ Object
This method is a shortcut to get field’s DOM id. Common usage: form.field_with(:dom_id => “foo”)
44 45 46 |
# File 'lib/mechanize/form/field.rb', line 44 def dom_id node['id'] end |
#query_value ⇒ Object
31 32 33 |
# File 'lib/mechanize/form/field.rb', line 31 def query_value [[@name, @value || '']] end |