Class: Roundtrip::Trip

Inherits:
Object
  • Object
show all
Defined in:
lib/roundtrip/trip.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, route, started_at) ⇒ Trip

Returns a new instance of Trip.



8
9
10
11
12
13
# File 'lib/roundtrip/trip.rb', line 8

def initialize(id, route, started_at)
  self.id = id
  self.route = route
  self.started_at = started_at
  self.checkpoints = []
end

Instance Attribute Details

#checkpointsObject

Returns the value of attribute checkpoints.



6
7
8
# File 'lib/roundtrip/trip.rb', line 6

def checkpoints
  @checkpoints
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/roundtrip/trip.rb', line 6

def id
  @id
end

#routeObject

Returns the value of attribute route.



6
7
8
# File 'lib/roundtrip/trip.rb', line 6

def route
  @route
end

#started_atObject

Returns the value of attribute started_at.



6
7
8
# File 'lib/roundtrip/trip.rb', line 6

def started_at
  @started_at
end

Class Method Details

.generate(route, opts = {}) ⇒ Object



34
35
36
# File 'lib/roundtrip/trip.rb', line 34

def self.generate(route, opts={})
  new(opts[:id] || SecureRandom.hex, route, Time.now)
end

Instance Method Details

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



29
30
31
# File 'lib/roundtrip/trip.rb', line 29

def ==(o)
  o.class == self.class && o.to_h == to_h
end

#to_hObject



20
21
22
23
24
25
26
27
# File 'lib/roundtrip/trip.rb', line 20

def to_h
  {
    :id  => id, 
    :route => route, 
    :started_at => started_at.iso8601(6), 
    :checkpoints => checkpoints.map{|cp| [cp[0], cp[1].iso8601(6)] }
  }
end

#to_json(*a) ⇒ Object



16
17
18
# File 'lib/roundtrip/trip.rb', line 16

def to_json(*a)
  to_h.to_json(*a)
end