Permalink
Browse files

Move some stuff to Base

  • Loading branch information...
1 parent 2c92e19 commit ebf4e2619de86584309135d07eca047734f9bd26 @joshuaclayton committed Feb 1, 2011
Showing with 15 additions and 19 deletions.
  1. +1 −0 lib/polylines.rb
  2. +11 −0 lib/polylines/base.rb
  3. +2 −10 lib/polylines/decoder.rb
  4. +1 −9 lib/polylines/encoder.rb
View
@@ -1,4 +1,5 @@
module Polylines
+ autoload :Base, "polylines/base"
autoload :Encoder, "polylines/encoder"
autoload :Decoder, "polylines/decoder"
end
View
@@ -0,0 +1,11 @@
+module Polylines
+ class Base
+ def self.step_5(number)
+ ~number
+ end
+
+ def self.step_7(five_bit_chunks)
+ five_bit_chunks.reverse
+ end
+ end
+end
@@ -1,5 +1,5 @@
module Polylines
- class Decoder
+ class Decoder < Base
def self.decode_polyline(polyline)
set = []
@@ -12,7 +12,7 @@ def self.decode_polyline(polyline)
end
charset
- end.map {|set| decode(set) }
+ end.map {|charset| decode(charset) }
points = [[points_with_deltas.shift, points_with_deltas.shift]]
@@ -55,20 +55,12 @@ def self.step_4(number)
number >> 1
end
- def self.step_5(number)
- ~number
- end
-
def self.step_6(five_bit_chunks)
five_bit_chunks.map do |chunk|
"%05b" % chunk
end.join
end
- def self.step_7(five_bit_chunks)
- five_bit_chunks.reverse
- end
-
def self.step_8(decimal_values)
decimal_values[0..-2].map {|value| 0x20 ^ value } << decimal_values.last
end
@@ -1,5 +1,5 @@
module Polylines
- class Encoder
+ class Encoder < Base
def self.encode_points(points)
delta_latitude, delta_longitude = 0, 0
@@ -40,10 +40,6 @@ def self.step_4(number)
number << 1
end
- def self.step_5(number)
- ~number
- end
-
def self.step_6(number)
[].tap do |numbers|
while number > 0 do
@@ -53,10 +49,6 @@ def self.step_6(number)
end
end
- def self.step_7(five_bit_chunks)
- five_bit_chunks.reverse
- end
-
def self.step_8(five_bit_chunks)
five_bit_chunks[0..-2].map {|chunk| 0x20 | chunk } << five_bit_chunks.last
end

0 comments on commit ebf4e26

Please sign in to comment.