Class: Hour
- Inherits:
-
Object
- Object
- Hour
- Defined in:
- lib/pomodoro/exts/hour.rb
Instance Attribute Summary collapse
-
#minutes ⇒ Object
readonly
Returns the value of attribute minutes.
Class Method Summary collapse
Instance Method Summary collapse
- #hours ⇒ Object
-
#initialize(hours, minutes = 0) ⇒ Hour
constructor
A new instance of Hour.
- #inspect ⇒ Object (also: #to_s)
Constructor Details
#initialize(hours, minutes = 0) ⇒ Hour
Returns a new instance of Hour.
13 14 15 |
# File 'lib/pomodoro/exts/hour.rb', line 13 def initialize(hours, minutes = 0) @minutes = (hours * 60) + minutes end |
Instance Attribute Details
#minutes ⇒ Object (readonly)
Returns the value of attribute minutes.
12 13 14 |
# File 'lib/pomodoro/exts/hour.rb', line 12 def minutes @minutes end |
Class Method Details
.now ⇒ Object
7 8 9 10 |
# File 'lib/pomodoro/exts/hour.rb', line 7 def self.now now = Time.now self.new(now.hour, now.min) end |
.parse(string) ⇒ Object
2 3 4 5 |
# File 'lib/pomodoro/exts/hour.rb', line 2 def self.parse(string) hours, minutes = string.split(':') self.new(hours.to_i, minutes.to_i) end |
Instance Method Details
#hours ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/pomodoro/exts/hour.rb', line 29 def hours if (@minutes / 60).round > (@minutes / 60) (@minutes / 60).round - 1 else (@minutes / 60).round end end |
#inspect ⇒ Object Also known as: to_s
54 55 56 |
# File 'lib/pomodoro/exts/hour.rb', line 54 def inspect "#{self.hours}:#{format('%02d', self.minutes_over_the_hour)}" end |