Class: Hour

Inherits:
Object
  • Object
show all
Defined in:
lib/pomodoro/exts/hour.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#minutesObject (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

.nowObject



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

#hoursObject



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

#inspectObject 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