lib/geo_swap/zone.rb in geo_swap-0.0.2 vs lib/geo_swap/zone.rb in geo_swap-0.1.0
- old
+ new
@@ -1,8 +1,9 @@
module GeoSwap
class Zone
- def initialize(longitude)
+ def initialize(latitude, longitude)
+ @latitude = latitude
@longitude = longitude.to_f
end
def number
@number ||= begin
@@ -12,8 +13,35 @@
end
end
def origin
@origin ||= ((number - 1) * 6) - 177
+ end
+
+ def letter
+ case @latitude
+ when 72..84 then 'X'
+ when 64...72 then 'W'
+ when 56...64 then 'V'
+ when 48...56 then 'U'
+ when 40...48 then 'T'
+ when 32...40 then 'S'
+ when 24...32 then 'R'
+ when 16...24 then 'Q'
+ when 8...16 then 'P'
+ when 0...8 then 'N'
+ when -8...0 then 'M'
+ when -16...-8 then 'L'
+ when -24...-16 then 'K'
+ when -32...-24 then 'J'
+ when -40...-32 then 'H'
+ when -48...-40 then 'G'
+ when -56...-48 then 'F'
+ when -64...-56 then 'E'
+ when -72...-64 then 'D'
+ when -80...-72 then 'C'
+ else
+ 'Z'
+ end
end
end
end