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
- #description ⇒ Object
- #duration ⇒ Object
- #finish ⇒ Object
- #indent ⇒ Object
-
#initialize(item, parent = nil) ⇒ TimedItem
constructor
A new instance of TimedItem.
- #percentage ⇒ Object
- #puts(*args) ⇒ Object
- #report ⇒ 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
#description ⇒ Object
43 44 45 |
# File 'lib/example_group_timer/timed_item.rb', line 43 def description item.description.strip end |
#duration ⇒ Object
18 19 20 |
# File 'lib/example_group_timer/timed_item.rb', line 18 def duration @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 (duration.to_f / parent.duration.to_f) * 100 end |
#puts(*args) ⇒ Object
47 48 49 |
# File 'lib/example_group_timer/timed_item.rb', line 47 def puts(*args) parent.puts *args end |
#report ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/example_group_timer/timed_item.rb', line 30 def report template = <<-EOS <li> <div class="example-group"> <span class="title">%s</span> <span class="duration">%.4f</span> <span class="share">%.1f%%</span> </div> </li> EOS puts template % [description, 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 |