Class: TimeInterval::TimePair

Inherits:
Object
  • Object
show all
Defined in:
lib/time_interval/time_pair.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_time, end_time) ⇒ TimePair

Returns a new instance of TimePair.



16
17
18
19
# File 'lib/time_interval/time_pair.rb', line 16

def initialize(start_time, end_time)
  @start_time = start_time
  @end_time = end_time
end

Instance Attribute Details

#end_timeObject (readonly)

Returns the value of attribute end_time.



14
15
16
# File 'lib/time_interval/time_pair.rb', line 14

def end_time
  @end_time
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



13
14
15
# File 'lib/time_interval/time_pair.rb', line 13

def start_time
  @start_time
end

Class Method Details

.parse(iso8601) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/time_interval/time_pair.rb', line 3

def self.parse(iso8601)
  halves = iso8601.split('/')

  fail ArgumentError unless halves.length == 2

  start_time, end_time = halves.map { |time| Time.parse time }

  new start_time, end_time
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



21
22
23
24
25
# File 'lib/time_interval/time_pair.rb', line 21

def ==(other)
  return false unless other.is_a? TimePair

  start_time == other.start_time && end_time == other.end_time
end

#iso8601Object



29
30
31
# File 'lib/time_interval/time_pair.rb', line 29

def iso8601
  "#{start_time.iso8601}/#{end_time.iso8601}"
end