Class: Stratagem::Crawler::Form

Inherits:
Object
  • Object
show all
Defined in:
lib/stratagem/crawler/form.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeForm

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

#actionObject

Returns the value of attribute action.



4
5
6
# File 'lib/stratagem/crawler/form.rb', line 4

def action
  @action
end

#buttonsObject

Returns the value of attribute buttons.



4
5
6
# File 'lib/stratagem/crawler/form.rb', line 4

def buttons
  @buttons
end

#inputsObject (readonly)

Returns the value of attribute inputs.



5
6
7
# File 'lib/stratagem/crawler/form.rb', line 5

def inputs
  @inputs
end

#methodObject

Returns the value of attribute method.



4
5
6
# File 'lib/stratagem/crawler/form.rb', line 4

def method
  @method
end

#pageObject

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_parametersObject



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_methodObject



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_keysObject



34
35
36
# File 'lib/stratagem/crawler/form.rb', line 34

def parameter_keys
  @parameter_keys ||= inputs.map {|input| input.name }
end

#password?Boolean

Returns:

  • (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