Class: BusinessTime::ParsedTime

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/business_time/parsed_time.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hour, min = 0, sec = 0) ⇒ ParsedTime

Returns a new instance of ParsedTime.


7
8
9
10
11
# File 'lib/business_time/parsed_time.rb', line 7

def initialize(hour, min = 0, sec = 0)
  @hour = hour
  @min = min
  @sec = sec
end

Instance Attribute Details

#hourObject (readonly)

Returns the value of attribute hour


5
6
7
# File 'lib/business_time/parsed_time.rb', line 5

def hour
  @hour
end

#minObject (readonly)

Returns the value of attribute min


5
6
7
# File 'lib/business_time/parsed_time.rb', line 5

def min
  @min
end

#secObject (readonly)

Returns the value of attribute sec


5
6
7
# File 'lib/business_time/parsed_time.rb', line 5

def sec
  @sec
end

Class Method Details

.parse(time_or_string) ⇒ Object


13
14
15
16
17
18
19
20
# File 'lib/business_time/parsed_time.rb', line 13

def self.parse(time_or_string)
  if time_or_string.is_a?(String)
    time = Time.parse(time_or_string)
  else
    time = time_or_string
  end
  new(time.hour, time.min, time.sec)
end

Instance Method Details

#-(other) ⇒ Object


26
27
28
# File 'lib/business_time/parsed_time.rb', line 26

def -(other)
  (hour - other.hour) * 3600 + (min - other.min) * 60 + sec - other.sec
end

#<=>(other) ⇒ Object


30
31
32
# File 'lib/business_time/parsed_time.rb', line 30

def <=>(other)
  [hour, min, sec] <=> [other.hour, other.min, other.sec]
end

#to_sObject


22
23
24
# File 'lib/business_time/parsed_time.rb', line 22

def to_s
  "#{hour}:#{min}:#{sec}"
end