Class: V900Track
- Inherits:
-
Object
- Object
- V900Track
- Defined in:
- lib/columbus3/v900track/v900track.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #[](i) ⇒ Object
- #add(v900_waypoint) ⇒ Object
- #bearing ⇒ Object
- #distance ⇒ Object
- #distance_aerial ⇒ Object
- #duration ⇒ Object
- #each(&block) ⇒ Object
- #end_date ⇒ Object
- #end_location ⇒ Object
- #first ⇒ Object
-
#initialize(hash) ⇒ V900Track
constructor
A new instance of V900Track.
- #last ⇒ Object
- #max_height ⇒ Object
- #max_height_idx ⇒ Object
- #max_speed ⇒ Object
- #max_speed_idx ⇒ Object
-
#metadata ⇒ Object
return a hash with all the metadata …
- #min_height ⇒ Object
- #min_height_idx ⇒ Object
- #min_speed ⇒ Object
- #min_speed_idx ⇒ Object
-
#points ⇒ Object
an alias for size.
- #range ⇒ Object
- #read(filename) ⇒ Object
- #save ⇒ Object
- #size ⇒ Object
-
#start_date ⇒ Object
statistics.
- #start_location ⇒ Object
-
#to_a ⇒ Object
to enumerate (till I can solve the each issue).
-
#to_s ⇒ Object
a slightly more robust implementation calls data in the same order in which the header is printed.
Constructor Details
#initialize(hash) ⇒ V900Track
Returns a new instance of V900Track.
9 10 11 12 13 14 15 16 |
# File 'lib/columbus3/v900track/v900track.rb', line 9 def initialize hash @filename = hash[:filename] if hash[:empty] @data = [] else read filename end end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
7 8 9 |
# File 'lib/columbus3/v900track/v900track.rb', line 7 def filename @filename end |
Instance Method Details
#[](i) ⇒ Object
58 59 60 |
# File 'lib/columbus3/v900track/v900track.rb', line 58 def [](i) @data[i] end |
#add(v900_waypoint) ⇒ Object
27 28 29 |
# File 'lib/columbus3/v900track/v900track.rb', line 27 def add v900_waypoint @data << v900_waypoint end |
#bearing ⇒ Object
124 125 126 |
# File 'lib/columbus3/v900track/v900track.rb', line 124 def bearing Geocoder::Calculations.compass_point(Geocoder::Calculations.bearing_between(first.lat_lon, last.lat_lon)) end |
#distance ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/columbus3/v900track/v900track.rb', line 132 def distance distance = 0 range.each do |i| distance += Geocoder::Calculations.distance_between(self[i].lat_lon, self[i-1].lat_lon, :units => :km) end distance end |
#distance_aerial ⇒ Object
128 129 130 |
# File 'lib/columbus3/v900track/v900track.rb', line 128 def distance_aerial Geocoder::Calculations.distance_between(first.lat_lon, last.lat_lon, :units => :km) end |
#duration ⇒ Object
80 81 82 |
# File 'lib/columbus3/v900track/v900track.rb', line 80 def duration last.time - first.time end |
#each(&block) ⇒ Object
50 51 52 |
# File 'lib/columbus3/v900track/v900track.rb', line 50 def each(&block) @data.each(&block) end |
#end_date ⇒ Object
76 77 78 |
# File 'lib/columbus3/v900track/v900track.rb', line 76 def end_date last.time end |
#end_location ⇒ Object
120 121 122 |
# File 'lib/columbus3/v900track/v900track.rb', line 120 def end_location Geocoder.address(last.lat_lon) end |
#first ⇒ Object
62 63 64 |
# File 'lib/columbus3/v900track/v900track.rb', line 62 def first @data[0] end |
#last ⇒ Object
66 67 68 |
# File 'lib/columbus3/v900track/v900track.rb', line 66 def last @data[size - 1] end |
#max_height ⇒ Object
96 97 98 |
# File 'lib/columbus3/v900track/v900track.rb', line 96 def max_height get :>, :height end |
#max_height_idx ⇒ Object
112 113 114 |
# File 'lib/columbus3/v900track/v900track.rb', line 112 def max_height_idx get_idx :>, :height end |
#max_speed ⇒ Object
88 89 90 |
# File 'lib/columbus3/v900track/v900track.rb', line 88 def max_speed get :>, :speed end |
#max_speed_idx ⇒ Object
104 105 106 |
# File 'lib/columbus3/v900track/v900track.rb', line 104 def max_speed_idx get_idx :>, :speed end |
#metadata ⇒ Object
return a hash with all the metadata … it could be a nice metamethod, creating a key for each public methods
142 143 144 145 146 147 148 |
# File 'lib/columbus3/v900track/v900track.rb', line 142 def = Hash.new [:start_date, :end_date, :duration, :size, :start_location, :end_location, :min_speed, :max_speed, :min_height, :max_height, :bearing, :distance, :distance_aerial].map { |x| [x] = self.send(x) } end |
#min_height ⇒ Object
92 93 94 |
# File 'lib/columbus3/v900track/v900track.rb', line 92 def min_height get :<, :height end |
#min_height_idx ⇒ Object
108 109 110 |
# File 'lib/columbus3/v900track/v900track.rb', line 108 def min_height_idx get_idx :<, :height end |
#min_speed ⇒ Object
84 85 86 |
# File 'lib/columbus3/v900track/v900track.rb', line 84 def min_speed get :<, :speed end |
#min_speed_idx ⇒ Object
100 101 102 |
# File 'lib/columbus3/v900track/v900track.rb', line 100 def min_speed_idx get_idx :<, :speed end |
#points ⇒ Object
an alias for size
36 37 38 |
# File 'lib/columbus3/v900track/v900track.rb', line 36 def points @data.size end |
#range ⇒ Object
40 41 42 |
# File 'lib/columbus3/v900track/v900track.rb', line 40 def range (0..self.size - 1) end |
#read(filename) ⇒ Object
18 19 20 21 |
# File 'lib/columbus3/v900track/v900track.rb', line 18 def read filename @filename = filename @data = CSV::read(filename, headers: true).each.map { |item| V900Waypoint.new(item) } end |
#save ⇒ Object
23 24 25 |
# File 'lib/columbus3/v900track/v900track.rb', line 23 def save File.open(@filename, 'w') {|f| f.write(to_s) } end |
#size ⇒ Object
31 32 33 |
# File 'lib/columbus3/v900track/v900track.rb', line 31 def size @data.size end |
#start_date ⇒ Object
statistics
72 73 74 |
# File 'lib/columbus3/v900track/v900track.rb', line 72 def start_date first.time end |
#start_location ⇒ Object
116 117 118 |
# File 'lib/columbus3/v900track/v900track.rb', line 116 def start_location Geocoder.address(first.lat_lon) end |
#to_a ⇒ Object
to enumerate (till I can solve the each issue)
45 46 47 |
# File 'lib/columbus3/v900track/v900track.rb', line 45 def to_a @data end |
#to_s ⇒ Object
a slightly more robust implementation calls data in the same order in which the header is printed
152 153 154 155 156 157 158 |
# File 'lib/columbus3/v900track/v900track.rb', line 152 def to_s string = "INDEX,TAG,DATE,TIME,LATITUDE N/S,LONGITUDE E/W,HEIGHT,SPEED,HEADING,VOX\n" @data.each do |data| string << data.to_s + "\n" end string end |