Class: SideToCapybara::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/side_to_capybara/base.rb

Direct Known Subclasses

Minitest

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(side_command) ⇒ Base

Returns a new instance of Base.



5
6
7
# File 'lib/side_to_capybara/base.rb', line 5

def initialize(side_command)
  @side_command = side_command
end

Instance Attribute Details

#side_commandObject (readonly)

Returns the value of attribute side_command.



4
5
6
# File 'lib/side_to_capybara/base.rb', line 4

def side_command
  @side_command
end

Instance Method Details

#commandObject



21
22
23
# File 'lib/side_to_capybara/base.rb', line 21

def command
  @side_command['command']
end

#commentObject



25
26
27
# File 'lib/side_to_capybara/base.rb', line 25

def comment
  @side_command['comment']
end

#idObject



29
30
31
# File 'lib/side_to_capybara/base.rb', line 29

def id
  @side_command['id']
end

#selectorObject



37
38
39
# File 'lib/side_to_capybara/base.rb', line 37

def selector
  _selector(target)
end

#selector_typeObject



33
34
35
# File 'lib/side_to_capybara/base.rb', line 33

def selector_type
  _selector_type(target)
end

#targetObject



9
10
11
# File 'lib/side_to_capybara/base.rb', line 9

def target
  @side_command['target']
end

#targetsObject



13
14
15
# File 'lib/side_to_capybara/base.rb', line 13

def targets
  @side_command['targets']
end

#translateObject

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



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 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

#valueObject



17
18
19
# File 'lib/side_to_capybara/base.rb', line 17

def value
  @side_command['value']
end