Class: CucumberMonitor::Step

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description, parent, id) ⇒ Step

Returns a new instance of Step.



7
8
9
10
11
12
13
14
# File 'lib/cucumber_monitor/step.rb', line 7

def initialize(description, parent, id)
  @description = description.strip
  code_first_part = parent.name.blank? ? parent.keyword.parameterize : parent.name.parameterize
  code_second_part = @description.parameterize
  @code = "#{code_first_part}-#{code_second_part}"
  @parent = parent
  @id = id
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



5
6
7
# File 'lib/cucumber_monitor/step.rb', line 5

def code
  @code
end

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/cucumber_monitor/step.rb', line 5

def description
  @description
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/cucumber_monitor/step.rb', line 5

def id
  @id
end

#parentObject

Returns the value of attribute parent.



5
6
7
# File 'lib/cucumber_monitor/step.rb', line 5

def parent
  @parent
end

Instance Method Details

#formattedObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cucumber_monitor/step.rb', line 54

def formatted
  output = ""
  if table_first_line?
    output << "<table>\n"
    output << "  <tr>\n"
    table_content.each do |th|
      output << "    <th>#{th}</th>\n"
    end
    output << "    <th>&nbsp;</th>"
    output << "  </tr>\n"
    output << "</table>\n" if table_last_line?
  elsif table_row?
    output << "  <tr>\n"
    table_content.each do |td|
      output << "    <td>#{td}</td>\n"
    end
    output << "    <td class='td_result'>&nbsp;</td>"
    output << "  </tr>\n"
    output << "</table>\n" if table_last_line?
  else
    output << description
  end
  output
end

#nextObject



24
25
26
# File 'lib/cucumber_monitor/step.rb', line 24

def next
  siblings_and_self.where(id: self.id + 1)
end

#not_a_tableObject



50
51
52
# File 'lib/cucumber_monitor/step.rb', line 50

def not_a_table
  !table?
end

#previousObject



20
21
22
# File 'lib/cucumber_monitor/step.rb', line 20

def previous
  siblings_and_self.where(id: self.id - 1)
end

#siblings_and_selfObject



16
17
18
# File 'lib/cucumber_monitor/step.rb', line 16

def siblings_and_self
  parent.steps
end

#table?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/cucumber_monitor/step.rb', line 28

def table?
  description.scan(/\|/).length >= 2 && description[0] == "|" && description[-1] == "|"
end

#table_contentObject



44
45
46
47
48
# File 'lib/cucumber_monitor/step.rb', line 44

def table_content
  if table?
    description.split("|").map{|l| l.strip}[1..-1]
  end
end

#table_first_line?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/cucumber_monitor/step.rb', line 32

def table_first_line?
  table? && (self.previous.blank? || self.previous.not_a_table)
end

#table_last_line?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/cucumber_monitor/step.rb', line 36

def table_last_line?
  table? && (self.next.blank? || self.next.not_a_table)
end

#table_row?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/cucumber_monitor/step.rb', line 40

def table_row?
  table? && !table_first_line?
end