Class: CucumberMonitor::Step
- Inherits:
-
Object
- Object
- CucumberMonitor::Step
- Defined in:
- lib/cucumber_monitor/step.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
Returns the value of attribute id.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #definition ⇒ Object
- #description_without_keyword ⇒ Object
- #formatted ⇒ Object
- #implemented? ⇒ Boolean
-
#initialize(description, parent, id) ⇒ Step
constructor
A new instance of Step.
- #named_params ⇒ Object
- #next ⇒ Object
- #not_a_table ⇒ Object
- #params ⇒ Object
- #previous ⇒ Object
- #siblings_and_self ⇒ Object
- #table? ⇒ Boolean
- #table_content ⇒ Object
- #table_first_line? ⇒ Boolean
- #table_last_line? ⇒ Boolean
- #table_row? ⇒ Boolean
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
#code ⇒ Object
Returns the value of attribute code.
5 6 7 |
# File 'lib/cucumber_monitor/step.rb', line 5 def code @code end |
#description ⇒ Object
Returns the value of attribute description.
5 6 7 |
# File 'lib/cucumber_monitor/step.rb', line 5 def description @description end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/cucumber_monitor/step.rb', line 5 def id @id end |
#parent ⇒ Object
Returns the value of attribute parent.
5 6 7 |
# File 'lib/cucumber_monitor/step.rb', line 5 def parent @parent end |
Instance Method Details
#definition ⇒ Object
58 59 60 |
# File 'lib/cucumber_monitor/step.rb', line 58 def definition Base.new.search_match(description_without_keyword) end |
#description_without_keyword ⇒ Object
16 17 18 |
# File 'lib/cucumber_monitor/step.rb', line 16 def description_without_keyword description.gsub(/^\S+\s/,'') end |
#formatted ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/cucumber_monitor/step.rb', line 84 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> </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'> </td>" output << " </tr>\n" output << "</table>\n" if table_last_line? else output << description end output end |
#implemented? ⇒ Boolean
80 81 82 |
# File 'lib/cucumber_monitor/step.rb', line 80 def implemented? !definition.nil? end |
#named_params ⇒ Object
74 75 76 77 78 |
# File 'lib/cucumber_monitor/step.rb', line 74 def named_params if implemented? && !table? definition.description[/\|(.*)\|/].gsub(/\|/,'').split(",").map{|p| p.strip} end end |
#next ⇒ Object
28 29 30 |
# File 'lib/cucumber_monitor/step.rb', line 28 def next siblings_and_self.where(id: self.id + 1) end |
#not_a_table ⇒ Object
54 55 56 |
# File 'lib/cucumber_monitor/step.rb', line 54 def not_a_table !table? end |
#params ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/cucumber_monitor/step.rb', line 62 def params if implemented? && !table? && !named_params.blank? result = description_without_keyword.match(definition.matcher) data = {} result.size.times do |n| next if n == 0 data.merge!(named_params[n-1].to_sym => result[n]) end data end end |
#previous ⇒ Object
24 25 26 |
# File 'lib/cucumber_monitor/step.rb', line 24 def previous siblings_and_self.where(id: self.id - 1) end |
#siblings_and_self ⇒ Object
20 21 22 |
# File 'lib/cucumber_monitor/step.rb', line 20 def siblings_and_self parent.steps end |
#table? ⇒ Boolean
32 33 34 |
# File 'lib/cucumber_monitor/step.rb', line 32 def table? description.scan(/\|/).length >= 2 && description[0] == "|" && description[-1] == "|" end |
#table_content ⇒ Object
48 49 50 51 52 |
# File 'lib/cucumber_monitor/step.rb', line 48 def table_content if table? description.split("|").map{|l| l.strip}[1..-1] end end |
#table_first_line? ⇒ Boolean
36 37 38 |
# File 'lib/cucumber_monitor/step.rb', line 36 def table_first_line? table? && (self.previous.blank? || self.previous.not_a_table) end |
#table_last_line? ⇒ Boolean
40 41 42 |
# File 'lib/cucumber_monitor/step.rb', line 40 def table_last_line? table? && (self.next.blank? || self.next.not_a_table) end |
#table_row? ⇒ Boolean
44 45 46 |
# File 'lib/cucumber_monitor/step.rb', line 44 def table_row? table? && !table_first_line? end |