class Clock
Attributes
hour[RW]
min[RW]
sec[RW]
usec[RW]
Public Class Methods
from_i(seconds)
click to toggle source
# File lib/a_clockwork_ruby/clock.rb, line 24 def self.from_i seconds self.new(seconds / 60**2 % 60**2, seconds / 60 % 60, seconds % 60) end
new(hour = nil, min = nil, sec = nil, usec = nil)
click to toggle source
# File lib/a_clockwork_ruby/clock.rb, line 5 def initialize(hour = nil, min = nil, sec = nil, usec = nil) if hour.nil? time = Time.now @hour = time.hour @min = time.min @sec = time.sec @usec = time.usec else @hour = hour @min = min || 0 @sec = sec || 0 @usec = usec || 0 end end
now()
click to toggle source
# File lib/a_clockwork_ruby/clock.rb, line 20 def self.now self.new end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/a_clockwork_ruby/clock.rb, line 73 def <=> other time = Time.now to_time_helper(time) <=> other.send(:to_time_helper, time) end
==(other)
click to toggle source
# File lib/a_clockwork_ruby/clock.rb, line 68 def == other time = Time.now to_time_helper(time) == other.send(:to_time_helper, time) end
hour=(hour)
click to toggle source
# File lib/a_clockwork_ruby/clock.rb, line 28 def hour= hour raise ArgumentError if hour < 0 or hour > 23 @hour = hour end
inspect()
click to toggle source
# File lib/a_clockwork_ruby/clock.rb, line 60 def inspect strfclock("%l:%M %p") end
min=(min)
click to toggle source
# File lib/a_clockwork_ruby/clock.rb, line 33 def min= min raise ArgumentError if min < 0 or min > 59 @min = min end
sec=(sec)
click to toggle source
# File lib/a_clockwork_ruby/clock.rb, line 38 def sec= sec raise ArgumentError if sec < 0 or sec > 59 @sec = sec end
strfclock(format)
click to toggle source
# File lib/a_clockwork_ruby/clock.rb, line 48 def strfclock format to_time.strftime(format) end
to_i()
click to toggle source
# File lib/a_clockwork_ruby/clock.rb, line 64 def to_i @sec + (@min * 60) + (@hour * 60**2) end
to_s()
click to toggle source
# File lib/a_clockwork_ruby/clock.rb, line 56 def to_s strfclock("%l:%M %p") end
to_time()
click to toggle source
# File lib/a_clockwork_ruby/clock.rb, line 52 def to_time to_time_helper(Time.now) end
usec=(usec)
click to toggle source
# File lib/a_clockwork_ruby/clock.rb, line 43 def usec= usec raise ArgumentError if usec < 0 or usec > 999999 @usec = usec end
Private Instance Methods
to_time_helper(time)
click to toggle source
# File lib/a_clockwork_ruby/clock.rb, line 80 def to_time_helper(time) Time.mktime(time.year, time.month, time.day, @hour, @min, @sec, @usec) end