Class: PlusCodes::CodeArea

Inherits:
Object
  • Object
show all
Defined in:
lib/plus_codes/code_area.rb

Overview

CodeArea

contains coordinates of a decoded Open Location Code(Plus+Codes).

The coordinates include the latitude and longitude of the lower left and upper right corners and the center of the bounding box for the area the code represents. Attributes:

latitude_lo: The latitude of the SW corner in degrees.
longitude_lo: The longitude of the SW corner in degrees.
latitude_hi: The latitude of the NE corner in degrees.
longitude_hi: The longitude of the NE corner in degrees.
latitude_center: The latitude of the center in degrees.
longitude_center: The longitude of the center in degrees.
code_length: The number of significant characters that were in the code.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(latitude_lo, longitude_lo, latitude_hi, longitude_hi, code_length) ⇒ CodeArea

Creates a [CodeArea].

Parameters:

  • latitude_lo (Numeric)

    the latitude of the SW corner in degrees

  • longitude_lo (Numeric)

    the longitude of the SW corner in degrees

  • latitude_hi (Numeric)

    the latitude of the NE corner in degrees

  • longitude_hi (Numeric)

    the longitude of the NE corner in degrees

  • code_length (Integer)

    the number of characters in the code, this excludes the separator



28
29
30
31
32
33
34
35
36
# File 'lib/plus_codes/code_area.rb', line 28

def initialize(latitude_lo, longitude_lo, latitude_hi, longitude_hi, code_length)
  @latitude_lo = latitude_lo
  @longitude_lo = longitude_lo
  @latitude_hi = latitude_hi
  @longitude_hi = longitude_hi
  @code_length = code_length
  @latitude_center = [@latitude_lo + (@latitude_hi - @latitude_lo) / 2, LATITUDE_MAX].min
  @longitude_center = [@longitude_lo + (@longitude_hi - @longitude_lo) / 2, LONGITUDE_MAX].min
end

Instance Attribute Details

#code_lengthObject

Returns the value of attribute code_length.



17
18
19
# File 'lib/plus_codes/code_area.rb', line 17

def code_length
  @code_length
end

#latitude_centerObject

Returns the value of attribute latitude_center.



17
18
19
# File 'lib/plus_codes/code_area.rb', line 17

def latitude_center
  @latitude_center
end

#latitude_hiObject

Returns the value of attribute latitude_hi.



17
18
19
# File 'lib/plus_codes/code_area.rb', line 17

def latitude_hi
  @latitude_hi
end

#latitude_loObject

Returns the value of attribute latitude_lo.



17
18
19
# File 'lib/plus_codes/code_area.rb', line 17

def latitude_lo
  @latitude_lo
end

#longitude_centerObject

Returns the value of attribute longitude_center.



17
18
19
# File 'lib/plus_codes/code_area.rb', line 17

def longitude_center
  @longitude_center
end

#longitude_hiObject

Returns the value of attribute longitude_hi.



17
18
19
# File 'lib/plus_codes/code_area.rb', line 17

def longitude_hi
  @longitude_hi
end

#longitude_loObject

Returns the value of attribute longitude_lo.



17
18
19
# File 'lib/plus_codes/code_area.rb', line 17

def longitude_lo
  @longitude_lo
end

Instance Method Details

#to_sObject



38
39
40
# File 'lib/plus_codes/code_area.rb', line 38

def to_s
  "lat_lo: #{@latitude_lo} long_lo: #{@longitude_lo} lat_hi: #{@latitude_hi} long_hi: #{@longitude_hi} code_len: #{@code_length}"
end