Class: GeoSwap::Zone

Inherits:
Object
  • Object
show all
Defined in:
lib/geo_swap/zone.rb

Instance Method Summary collapse

Constructor Details

#initialize(latitude, longitude) ⇒ Zone

Returns a new instance of Zone.



3
4
5
6
# File 'lib/geo_swap/zone.rb', line 3

def initialize(latitude, longitude)
  @latitude = latitude
  @longitude = longitude.to_f
end

Instance Method Details

#letterObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/geo_swap/zone.rb', line 20

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

#numberObject



8
9
10
11
12
13
14
# File 'lib/geo_swap/zone.rb', line 8

def number
  @number ||= begin
    number = ((@longitude + 180.0) / 6.0).floor + 1
    #special case for longitude 180.0
    (number > 60) ? 60 : number
  end
end

#originObject



16
17
18
# File 'lib/geo_swap/zone.rb', line 16

def origin
  @origin ||= ((number - 1) * 6) - 177
end