Class: StepStats::Step

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#definitionObject

Returns the value of attribute definition.



3
4
5
# File 'lib/step_stats/step.rb', line 3

def definition
  @definition
end

#locationObject

Returns the value of attribute location.



3
4
5
# File 'lib/step_stats/step.rb', line 3

def location
  @location
end

#nameObject

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

#avgObject



29
30
31
# File 'lib/step_stats/step.rb', line 29

def avg
  (total / count.to_f).round(3)
end

#countObject



37
38
39
# File 'lib/step_stats/step.rb', line 37

def count
  durations.count
end

#durationsObject



13
14
15
# File 'lib/step_stats/step.rb', line 13

def durations
  @durations || @step_entries.map{|step| step[:duration]}
end

#maxObject



25
26
27
# File 'lib/step_stats/step.rb', line 25

def max
  durations.max.to_f.round(3)
end

#minObject



21
22
23
# File 'lib/step_stats/step.rb', line 21

def min
  durations.min.to_f.round(3)
end

#stddevObject



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_dataObject



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

#totalObject



33
34
35
# File 'lib/step_stats/step.rb', line 33

def total
  durations.sum
end