Class: WebMinion::Step

Inherits:
Object
  • Object
show all
Defined in:
lib/web_minion/step.rb

Overview

A Step represents the individual operation that the bot will perform. This often includes grabbing an element from the DOM tree, or performing some operation on an element that has already been found.

Constant Summary collapse

VALID_METHODS =
{
  select: [
    :field,
    :radio_button,
    :first_radio_button,
    :checkbox
  ],
  main_methods: [
    :set_file_upload,
    :get_field,
    :get_form,
    :go,
    :select,
    :click,
    :click_button_in_form,
    :submit,
    :fill_in_input,
    :url_equals,
    :value_equals,
    :body_includes,
    :save_page_html,
    :save_value
  ]
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fields = {}) ⇒ Step

Returns a new instance of Step.



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/web_minion/step.rb', line 36

def initialize(fields = {})
  fields.each_pair do |k, v|
    if valid_method?(k.to_sym)
      send("method=", k)
      @target = v
    else
      send("#{k}=", v)
    end
  end

  replace_all_variables
end

Instance Attribute Details

#is_validatorObject

Returns the value of attribute is_validator.



8
9
10
# File 'lib/web_minion/step.rb', line 8

def is_validator
  @is_validator
end

#methodObject

Returns the value of attribute method.



8
9
10
# File 'lib/web_minion/step.rb', line 8

def method
  @method
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/web_minion/step.rb', line 8

def name
  @name
end

#retain_elementObject

Returns the value of attribute retain_element.



8
9
10
# File 'lib/web_minion/step.rb', line 8

def retain_element
  @retain_element
end

#saved_valuesObject (readonly)

Returns the value of attribute saved_values.



9
10
11
# File 'lib/web_minion/step.rb', line 9

def saved_values
  @saved_values
end

#skippableObject

Returns the value of attribute skippable.



8
9
10
# File 'lib/web_minion/step.rb', line 8

def skippable
  @skippable
end

#targetObject

Returns the value of attribute target.



8
9
10
# File 'lib/web_minion/step.rb', line 8

def target
  @target
end

#valueObject

Returns the value of attribute value.



8
9
10
# File 'lib/web_minion/step.rb', line 8

def value
  @value
end

#varsObject

Returns the value of attribute vars.



9
10
11
# File 'lib/web_minion/step.rb', line 9

def vars
  @vars
end

Instance Method Details

#perform(bot, element = nil, saved_values) ⇒ Object



53
54
55
# File 'lib/web_minion/step.rb', line 53

def perform(bot, element = nil, saved_values)
  bot.execute_step(@method, @target, @value, element, saved_values)
end

#retain?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/web_minion/step.rb', line 63

def retain?
  retain_element
end

#valid_method?(method) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
75
76
77
# File 'lib/web_minion/step.rb', line 71

def valid_method?(method)
  split = method.to_s.split("/").map(&:to_sym)
  if split.count > 1
    return true if VALID_METHODS[split[0]].include?(split[1])
  end
  VALID_METHODS[:main_methods].include?(method)
end

#validator?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/web_minion/step.rb', line 67

def validator?
  is_validator
end