Class: ScavengerHunt::Time

Inherits:
Object
  • Object
show all
Defined in:
lib/scavenger_hunt/app/models/scavenger_hunt/time.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seconds) ⇒ Time

Returns a new instance of Time



4
5
6
# File 'lib/scavenger_hunt/app/models/scavenger_hunt/time.rb', line 4

def initialize(seconds)
  @seconds = seconds
end

Instance Attribute Details

#secondsObject (readonly)

Returns the value of attribute seconds



2
3
4
# File 'lib/scavenger_hunt/app/models/scavenger_hunt/time.rb', line 2

def seconds
  @seconds
end

Instance Method Details

#+(other_time) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/scavenger_hunt/app/models/scavenger_hunt/time.rb', line 8

def +(other_time)
  case other_time
  when ScavengerHunt::Time
    return self.class.new(seconds + other_time.seconds)
  else
    return self.class.new(seconds + other_time)
  end
end

#to_sObject



17
18
19
# File 'lib/scavenger_hunt/app/models/scavenger_hunt/time.rb', line 17

def to_s
  Time.at(seconds).utc.strftime("%H:%M:%S")
end