Class: Stratagem::Crawler::Form
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#buttons ⇒ Object
Returns the value of attribute buttons.
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#method ⇒ Object
Returns the value of attribute method.
-
#page ⇒ Object
Returns the value of attribute page.
Instance Method Summary collapse
- #<<(input) ⇒ Object
- #generate_parameters ⇒ Object
- #implied_method ⇒ Object
-
#initialize ⇒ Form
constructor
A new instance of Form.
- #parameter_keys ⇒ Object
- #password? ⇒ Boolean
- #submit(&block) ⇒ Object
Constructor Details
#initialize ⇒ Form
Returns a new instance of Form.
7 8 9 10 |
# File 'lib/stratagem/crawler/form.rb', line 7 def initialize @inputs = [] @buttons = [] end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
4 5 6 |
# File 'lib/stratagem/crawler/form.rb', line 4 def action @action end |
#buttons ⇒ Object
Returns the value of attribute buttons.
4 5 6 |
# File 'lib/stratagem/crawler/form.rb', line 4 def @buttons end |
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
5 6 7 |
# File 'lib/stratagem/crawler/form.rb', line 5 def inputs @inputs end |
#method ⇒ Object
Returns the value of attribute method.
4 5 6 |
# File 'lib/stratagem/crawler/form.rb', line 4 def method @method end |
#page ⇒ Object
Returns the value of attribute page.
4 5 6 |
# File 'lib/stratagem/crawler/form.rb', line 4 def page @page end |
Instance Method Details
#<<(input) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/stratagem/crawler/form.rb', line 12 def << (input) if (input.kind_of?(Button)) @buttons << input else @inputs << input end end |
#generate_parameters ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/stratagem/crawler/form.rb', line 38 def generate_parameters params = {} inputs.each do |input| params[input.name] = input.value end params end |
#implied_method ⇒ Object
20 21 22 23 |
# File 'lib/stratagem/crawler/form.rb', line 20 def implied_method implied = inputs.find {|i| i.name == '_method' } implied ? implied.value : nil end |
#parameter_keys ⇒ Object
34 35 36 |
# File 'lib/stratagem/crawler/form.rb', line 34 def parameter_keys @parameter_keys ||= inputs.map {|input| input.name } end |
#password? ⇒ Boolean
26 27 28 |
# File 'lib/stratagem/crawler/form.rb', line 26 def password? !(inputs.find {|i| i.type == 'password' }.nil?) end |
#submit(&block) ⇒ Object
30 31 32 |
# File 'lib/stratagem/crawler/form.rb', line 30 def submit(&block) response = block.call(action, generate_parameters) end |