Class: BenchPress::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/bench_press/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runnables) ⇒ Result

Returns a new instance of Result.



5
6
7
# File 'lib/bench_press/result.rb', line 5

def initialize(runnables)
  @runnables = runnables
end

Instance Attribute Details

#runnablesObject (readonly)

Returns the value of attribute runnables.



3
4
5
# File 'lib/bench_press/result.rb', line 3

def runnables
  @runnables
end

Instance Method Details

#evaluateObject



9
10
11
12
13
# File 'lib/bench_press/result.rb', line 9

def evaluate
  sort
  grade
  self
end

#fastestObject



20
21
22
# File 'lib/bench_press/result.rb', line 20

def fastest
  runnables.first
end

#gradeObject



36
37
38
39
40
41
# File 'lib/bench_press/result.rb', line 36

def grade
  runnables.each do |r|
    r.fastest = fastest == r
    r.percent_slower = percentage_slower(r.run_time)
  end
end

#longest_nameObject



28
29
30
# File 'lib/bench_press/result.rb', line 28

def longest_name
  runnables.sort_by {|r| r.name.size}.last.name
end

#longest_run_timeObject



32
33
34
# File 'lib/bench_press/result.rb', line 32

def longest_run_time
  runnables.sort_by {|r| r.run_time.to_s.size}.last.run_time.to_s
end

#slowestObject



24
25
26
# File 'lib/bench_press/result.rb', line 24

def slowest
  runnables.last
end

#sortObject



15
16
17
18
# File 'lib/bench_press/result.rb', line 15

def sort
  runnables.each {|r| r.run}
  @runnables = runnables.sort_by {|r| r.run_time}
end