Class: Polylines::Decoder

Inherits:
Base
  • Object
show all
Defined in:
lib/polylines/decoder.rb

Instance Attribute Summary

Attributes inherited from Base

#current_value, #negative

Class Method Summary collapse

Methods inherited from Base

#decode!, #decoding?, #encode!, #encoding?, #initialize, #step_10, #step_11, #step_2, #step_3, #step_4, #step_5, #step_6, #step_7, #step_8, transform_to_array_of_lat_lng_and_deltas

Constructor Details

This class inherits a constructor from Polylines::Base

Class Method Details

.decode(string, precision = 1e5) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/polylines/decoder.rb', line 19

def self.decode(string, precision = 1e5)
  self.new(string).tap do |decoding|
    decoding.step_11
    decoding.step_10
    decoding.step_8
    decoding.step_7
    decoding.step_6
    decoding.step_5
    decoding.step_4
    decoding.step_3
    decoding.step_2 precision
  end.current_value
end

.decode_polyline(polyline, precision = 1e5) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/polylines/decoder.rb', line 3

def self.decode_polyline(polyline, precision = 1e5)
  points_with_deltas = transform_to_array_of_lat_lng_and_deltas(polyline,
                                                                precision)

  [].tap do |points|
    points << [points_with_deltas.shift, points_with_deltas.shift]

    while points_with_deltas.size > 1
      points << [
        points.last[0] + points_with_deltas.shift,
        points.last[1] + points_with_deltas.shift
      ]
    end
  end
end