Class: StepStats::Step
- Inherits:
-
Object
- Object
- StepStats::Step
- Defined in:
- lib/step_stats/step.rb
Instance Attribute Summary collapse
-
#definition ⇒ Object
Returns the value of attribute definition.
-
#location ⇒ Object
Returns the value of attribute location.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #add(step_entry) ⇒ Object
- #avg ⇒ Object
- #count ⇒ Object
- #durations ⇒ Object
-
#initialize(step_def_name, step_def_location) ⇒ Step
constructor
A new instance of Step.
- #max ⇒ Object
- #min ⇒ Object
- #stddev ⇒ Object
- #to_chart_data ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize(step_def_name, step_def_location) ⇒ Step
Returns a new instance of Step.
5 6 7 8 9 10 11 |
# File 'lib/step_stats/step.rb', line 5 def initialize(step_def_name, step_def_location) @name = step_def_name @location = step_def_location # An Array of hashs with duration, status and location # step_info = {duration: 5.21692, status: :pass, location: 'feature/...feature:219'} @step_entries = [] end |
Instance Attribute Details
#definition ⇒ Object
Returns the value of attribute definition.
3 4 5 |
# File 'lib/step_stats/step.rb', line 3 def definition @definition end |
#location ⇒ Object
Returns the value of attribute location.
3 4 5 |
# File 'lib/step_stats/step.rb', line 3 def location @location end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/step_stats/step.rb', line 3 def name @name end |
Instance Method Details
#add(step_entry) ⇒ Object
17 18 19 |
# File 'lib/step_stats/step.rb', line 17 def add step_entry @step_entries << step_entry end |
#avg ⇒ Object
29 30 31 |
# File 'lib/step_stats/step.rb', line 29 def avg (total / count.to_f).round(3) end |
#count ⇒ Object
37 38 39 |
# File 'lib/step_stats/step.rb', line 37 def count durations.count end |
#durations ⇒ Object
13 14 15 |
# File 'lib/step_stats/step.rb', line 13 def durations @durations || @step_entries.map{|step| step[:duration]} end |
#max ⇒ Object
25 26 27 |
# File 'lib/step_stats/step.rb', line 25 def max durations.max.to_f.round(3) end |
#min ⇒ Object
21 22 23 |
# File 'lib/step_stats/step.rb', line 21 def min durations.min.to_f.round(3) end |
#stddev ⇒ Object
41 42 43 44 45 46 |
# File 'lib/step_stats/step.rb', line 41 def stddev return 0.to_f if count == 1 total = durations.inject(0){|accum, i| accum +(i-avg)**2 } variance = total/(count - 1).to_f Math.sqrt(variance).round(3) end |
#to_chart_data ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/step_stats/step.rb', line 48 def to_chart_data @step_entries.map(&:values).each_with_index.map do |s, index| step_entry = [(index + 1).to_s,s[0]] if s[1] == :passed step_entry << "green" else step_entry << "red" end step_entry << "Location: #{s[2]} \n Time: #{s[0]} seconds" step_entry end.to_s end |
#total ⇒ Object
33 34 35 |
# File 'lib/step_stats/step.rb', line 33 def total durations.sum end |