class SideToCapybara::Base

Attributes

side_command[R]

Public Class Methods

new(side_command) click to toggle source
# File lib/side_to_capybara/base.rb, line 5
def initialize(side_command)
  @side_command = side_command
end

Public Instance Methods

command() click to toggle source
# File lib/side_to_capybara/base.rb, line 21
def command
  @side_command['command']
end
comment() click to toggle source
# File lib/side_to_capybara/base.rb, line 25
def comment
  @side_command['comment']
end
id() click to toggle source
# File lib/side_to_capybara/base.rb, line 29
def id
  @side_command['id']
end
selector() click to toggle source
# File lib/side_to_capybara/base.rb, line 37
def selector
  _selector(target)
end
selector_type() click to toggle source
# File lib/side_to_capybara/base.rb, line 33
def selector_type
  _selector_type(target)
end
target() click to toggle source
# File lib/side_to_capybara/base.rb, line 9
def target
  @side_command['target']
end
targets() click to toggle source
# File lib/side_to_capybara/base.rb, line 13
def targets
  @side_command['targets']
end
translate() click to toggle source

returns the translation of the command or a warning if the command can't be translated

# File lib/side_to_capybara/base.rb, line 42
def translate
  method_id = command.gsub(/([a-z])([A-Z])/, '\1_\2').downcase
  if self.class.public_method_defined?(method_id)
    # the translation itself
    translation = public_send(method_id)
    return "# WARNING: '#{command}' found but the selector_type '#{selector_type}' is unhandled." if translation.nil?

    # add the alternative selectors as comments if present
    if targets.size > 1
      "#{commented_targets.join("\n")}\n#{translation}"
    else
      translation
    end
  else
    "# WARNING: Conversion for '#{command}' not found."
  end
end
value() click to toggle source
# File lib/side_to_capybara/base.rb, line 17
def value
  @side_command['value']
end

Private Instance Methods

_selector(target) click to toggle source
# File lib/side_to_capybara/base.rb, line 66
def _selector(target)
  split_target(target).last
end
_selector_type(target) click to toggle source
# File lib/side_to_capybara/base.rb, line 70
def _selector_type(target)
  split_target(target).first
end
commented_targets() click to toggle source
# File lib/side_to_capybara/base.rb, line 74
def commented_targets
  targets.map { |target| "# #{_selector_type(target.first)}: #{_selector(target.first)}" }.uniq
end
split_target(target) click to toggle source
# File lib/side_to_capybara/base.rb, line 62
def split_target(target)
  /^(\w+)=(.*)$/.match(target)[1..2]
end