Class: Roundtrip::Trip
- Inherits:
-
Object
- Object
- Roundtrip::Trip
- Defined in:
- lib/roundtrip/trip.rb
Instance Attribute Summary collapse
-
#checkpoints ⇒ Object
Returns the value of attribute checkpoints.
-
#id ⇒ Object
Returns the value of attribute id.
-
#route ⇒ Object
Returns the value of attribute route.
-
#started_at ⇒ Object
Returns the value of attribute started_at.
Class Method Summary collapse
Instance Method Summary collapse
- #==(o) ⇒ Object (also: #eql?)
-
#initialize(id, route, started_at) ⇒ Trip
constructor
A new instance of Trip.
- #to_h ⇒ Object
- #to_json(*a) ⇒ Object
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
#checkpoints ⇒ Object
Returns the value of attribute checkpoints.
6 7 8 |
# File 'lib/roundtrip/trip.rb', line 6 def checkpoints @checkpoints end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/roundtrip/trip.rb', line 6 def id @id end |
#route ⇒ Object
Returns the value of attribute route.
6 7 8 |
# File 'lib/roundtrip/trip.rb', line 6 def route @route end |
#started_at ⇒ Object
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_h ⇒ Object
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 |