Class: ExampleGroupTimer::TimedItem
- Inherits:
-
Object
- Object
- ExampleGroupTimer::TimedItem
- Defined in:
- lib/example_group_timer/timed_item.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#item ⇒ Object
readonly
Returns the value of attribute item.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #duration ⇒ Object
- #finish ⇒ Object
- #indent ⇒ Object
-
#initialize(item, parent = nil) ⇒ TimedItem
constructor
A new instance of TimedItem.
- #percentage ⇒ Object
- #report_header ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(item, parent = nil) ⇒ TimedItem
Returns a new instance of TimedItem.
5 6 7 8 |
# File 'lib/example_group_timer/timed_item.rb', line 5 def initialize(item, parent = nil) @item, @parent = item, parent start end |
Instance Attribute Details
#item ⇒ Object (readonly)
Returns the value of attribute item.
3 4 5 |
# File 'lib/example_group_timer/timed_item.rb', line 3 def item @item end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
3 4 5 |
# File 'lib/example_group_timer/timed_item.rb', line 3 def parent @parent end |
Instance Method Details
#duration ⇒ Object
18 19 20 |
# File 'lib/example_group_timer/timed_item.rb', line 18 def duration '%.5f' % [@finished_at - @started_at] end |
#finish ⇒ Object
14 15 16 |
# File 'lib/example_group_timer/timed_item.rb', line 14 def finish @finished_at = Time.now end |
#indent ⇒ Object
22 23 24 |
# File 'lib/example_group_timer/timed_item.rb', line 22 def indent parent.indent + 1 end |
#percentage ⇒ Object
26 27 28 |
# File 'lib/example_group_timer/timed_item.rb', line 26 def percentage ('%.1f%' % [(duration.to_f / parent.duration.to_f) * 100]).rjust(5) end |
#report_header ⇒ Object
30 31 32 33 |
# File 'lib/example_group_timer/timed_item.rb', line 30 def report_header truncated = ((' ' * indent) + item.description.strip)[0..59].ljust(60) puts "#{truncated} #{duration} #{percentage}" end |
#start ⇒ Object
10 11 12 |
# File 'lib/example_group_timer/timed_item.rb', line 10 def start @started_at = Time.now end |