Class: WhereWasI::Track
- Inherits:
-
Object
- Object
- WhereWasI::Track
- Defined in:
- lib/where_was_i/track.rb
Overview
a series of sequential [lat, lon, elevation] points
Instance Attribute Summary collapse
-
#end_location ⇒ Object
readonly
Returns the value of attribute end_location.
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#start_location ⇒ Object
readonly
Returns the value of attribute start_location.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_point(lat:, lon:, elevation:, time:) ⇒ Object
add a point to the track.
-
#at(time) ⇒ Hash?
return the interpolated location for the given time or nil if time is outside the track’s start..end.
-
#in_time_range?(time) ⇒ Boolean
is the supplied time covered by this track?.
-
#initialize ⇒ Track
constructor
A new instance of Track.
-
#time_range ⇒ Object
the time range covered by this track.
Constructor Details
#initialize ⇒ Track
Returns a new instance of Track.
18 19 20 |
# File 'lib/where_was_i/track.rb', line 18 def initialize @points = {} end |
Instance Attribute Details
#end_location ⇒ Object (readonly)
Returns the value of attribute end_location.
8 9 10 |
# File 'lib/where_was_i/track.rb', line 8 def end_location @end_location end |
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
8 9 10 |
# File 'lib/where_was_i/track.rb', line 8 def end_time @end_time end |
#start_location ⇒ Object (readonly)
Returns the value of attribute start_location.
8 9 10 |
# File 'lib/where_was_i/track.rb', line 8 def start_location @start_location end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
8 9 10 |
# File 'lib/where_was_i/track.rb', line 8 def start_time @start_time end |
Class Method Details
.array_to_hash(a) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/where_was_i/track.rb', line 10 def self.array_to_hash(a) { lat: a[0], lon: a[1], elevation: a[2] } end |
Instance Method Details
#add_point(lat:, lon:, elevation:, time:) ⇒ Object
add a point to the track
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/where_was_i/track.rb', line 28 def add_point(lat:, lon:, elevation:, time:) time = Time.parse(time) if ! time.is_a?(Time) current = [lat, lon, elevation] if @start_time.nil? || time < @start_time @start_time = time @start_location = current end if @end_time.nil? || time > @end_time @end_time = time @end_location = current end @points[time.to_i] = current true end |
#at(time) ⇒ Hash?
return the interpolated location for the given time or nil if time is outside the track’s start..end
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/where_was_i/track.rb', line 71 def at(time) if time.is_a?(String) time = Time.parse(time) end if time.is_a?(Fixnum) time = Time.at(time) end raise ArgumentError, "time must be a Time,String, or Fixnum" if ! time.is_a?(Time) return nil if ! in_time_range?(time) @interp ||= Interpolate::Points.new(@points) data = @interp.at(time.to_i) self.class.array_to_hash(data) end |
#in_time_range?(time) ⇒ Boolean
is the supplied time covered by this track?
59 60 61 62 |
# File 'lib/where_was_i/track.rb', line 59 def in_time_range?(time) time = Time.parse(time) if ! time.is_a?(Time) time_range.cover?(time) end |
#time_range ⇒ Object
the time range covered by this track
51 52 53 |
# File 'lib/where_was_i/track.rb', line 51 def time_range start_time..end_time end |