Method: OpenLocationCode::Decoder#process

Defined in:
lib/open_location_code/decoder.rb

#processCodeArea

Decode opne location code

Returns:



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
44
# File 'lib/open_location_code/decoder.rb', line 18

def process
  unless full?
    raise OLCError, "Passed Open Location Code is not a valid full code: #{code}"
  end

  # Strip out separator character (we've already established the code is
  # valid so the maximum is one), padding characters and convert to upper case.
  code.sub!(SEPARATOR, '')
  code.sub!(/#{PADDING_CHARACTER}+/, '')
  code.upcase!

  # Decode the lat/lng pair component.
  code_area = decode_pairs(code[0, PAIR_CODE_LENGTH])

  # If there is a grid refinement component, decode that.
  return code_area if code.length <= PAIR_CODE_LENGTH

  grid_area = decode_grid(code[PAIR_CODE_LENGTH, code.length - 1])

  CodeArea.new(
    code_area.latitude_lo + grid_area.latitude_lo,
    code_area.longitude_lo + grid_area.longitude_lo,
    code_area.latitude_lo + grid_area.latitude_hi,
    code_area.longitude_lo + grid_area.longitude_hi,
    code_area.code_length + grid_area.code_length
  )
end