class Timing::HourMinutesSeconds

Constants

HH_MM_SS_REGEX

Attributes

hour[R]
minutes[R]
seconds[R]

Public Class Methods

new(hour, minutes=0, seconds=0) click to toggle source
# File lib/timing/hour_minutes_seconds.rb, line 8
def initialize(hour, minutes=0, seconds=0)
  raise ArgumentError, "Invalid hour #{hour}" if !hour.is_a?(Integer) || hour < 0 || hour > 23
  raise ArgumentError, "Invalid minutes #{minutes}" if !minutes.is_a?(Integer) || minutes < 0 || minutes > 59
  raise ArgumentError, "Invalid minutes #{seconds}" if !seconds.is_a?(Integer) || seconds < 0 || seconds > 59

  @hour = hour
  @minutes = minutes
  @seconds = seconds
end
parse(expression) click to toggle source
# File lib/timing/hour_minutes_seconds.rb, line 71
def self.parse(expression)
  match = expression.to_s.match HH_MM_SS_REGEX
  raise ArgumentError, "Invalid expression #{expression}" unless match
  new(*match.names.map { |n| (match[n] || 0).to_i })
end

Public Instance Methods

<(other) click to toggle source
# File lib/timing/hour_minutes_seconds.rb, line 41
def <(other)
  raise ArgumentError, "Invalid argument #{other}" unless other.is_a?(HourMinutesSeconds)

  (hour < other.hour) ||
  (hour == other.hour && minutes < other.minutes) ||
  (hour == other.hour && minutes == other.minutes && seconds < other.seconds)
end
<=(other) click to toggle source
# File lib/timing/hour_minutes_seconds.rb, line 53
def <=(other)
  self < other || self == other
end
<=>(other) click to toggle source
# File lib/timing/hour_minutes_seconds.rb, line 57
def <=>(other)
  if self == other
    0
  elsif self > other
    1
  else
    -1
  end
end
==(other) click to toggle source
# File lib/timing/hour_minutes_seconds.rb, line 24
def ==(other)
  other.kind_of?(self.class) && hash == other.hash
end
Also aliased as: eql?
>(other) click to toggle source
# File lib/timing/hour_minutes_seconds.rb, line 33
def >(other)
  raise ArgumentError, "Invalid argument #{other}" unless other.is_a?(HourMinutesSeconds)

  (hour > other.hour) ||
  (hour == other.hour && minutes > other.minutes) ||
  (hour == other.hour && minutes == other.minutes && seconds > other.seconds)
end
>=(other) click to toggle source
# File lib/timing/hour_minutes_seconds.rb, line 49
def >=(other)
  self > other || self == other
end
between?(from, to) click to toggle source
# File lib/timing/hour_minutes_seconds.rb, line 67
def between?(from, to)
  self >= from && self <= to
end
eql?(other)
Alias for: ==
hash() click to toggle source
# File lib/timing/hour_minutes_seconds.rb, line 29
def hash
  [hour, minutes, seconds].hash
end
inspect()
Alias for: iso8601
iso8601() click to toggle source
# File lib/timing/hour_minutes_seconds.rb, line 18
def iso8601
  [hour, minutes, seconds].map { |d| d.to_s.rjust(2, '0') }.join(':')
end
Also aliased as: to_s, inspect
to_s()
Alias for: iso8601