Class: GoogleMapTimeline
- Inherits:
-
Object
- Object
- GoogleMapTimeline
- Defined in:
- lib/google_timeline/google_map_timeline.rb
Instance Attribute Summary collapse
-
#file_path ⇒ Object
Returns the value of attribute file_path.
-
#home_coordinate ⇒ Object
Returns the value of attribute home_coordinate.
Instance Method Summary collapse
- #get_timeline_url(args) ⇒ Object
-
#initialize(file_path, home_coordinate) ⇒ GoogleMapTimeline
constructor
A new instance of GoogleMapTimeline.
Constructor Details
#initialize(file_path, home_coordinate) ⇒ GoogleMapTimeline
Returns a new instance of GoogleMapTimeline.
5 6 7 8 |
# File 'lib/google_timeline/google_map_timeline.rb', line 5 def initialize(file_path, home_coordinate) self.file_path = file_path self.home_coordinate = home_coordinate end |
Instance Attribute Details
#file_path ⇒ Object
Returns the value of attribute file_path.
3 4 5 |
# File 'lib/google_timeline/google_map_timeline.rb', line 3 def file_path @file_path end |
#home_coordinate ⇒ Object
Returns the value of attribute home_coordinate.
2 3 4 |
# File 'lib/google_timeline/google_map_timeline.rb', line 2 def home_coordinate @home_coordinate end |
Instance Method Details
#get_timeline_url(args) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/google_timeline/google_map_timeline.rb', line 10 def get_timeline_url(args) op_hash = {} url=default_map coordinates = [] value = self.file_path key = Date.parse(value.split("/").last.split(".").first.gsub("history-", "")) rescue nil op_hash[:date] = key if key.nil? == false and File.exists?(value) kml = File.read(value) doc = Nokogiri::XML(kml) coordinates = doc.search('coordinates').map{|c| c.content.split(" ")}.flatten.map{|co| co.split(",")[0..1].reverse.map{|co1| co1.to_f}} rescue [] if coordinates.is_a?(Array) location_str = polylines_encoding(coordinates) if location_str.length > 1900 coordinates_dup = coordinates.dup while location_str.length > 1900 do coordinates_dup = coordinates_dup.values_at(* coordinates_dup.each_index.select {|i| i.even?}) location_str = polylines_encoding(coordinates_dup) end end url = location_url(location_str) end end op_hash[:url] = url if (args.empty?)==false and (args.select{|a| a.is_a?(Hash) and a[:distance]==true}.first).nil? == false distance = {:value => overall_distance(coordinates), :unit=>"meter"} op_hash[:distance] = distance end return op_hash end |