Class: CartoJson::Point
- Inherits:
-
Object
- Object
- CartoJson::Point
- Includes:
- Shape
- Defined in:
- lib/carto_json/point.rb
Direct Known Subclasses
Instance Method Summary collapse
- #==(point) ⇒ Object
-
#initialize(input) ⇒ Point
constructor
A new instance of Point.
- #to_hash ⇒ Object
- #to_hash_for_array ⇒ Object
Methods included from Shape
included, #to_json, #to_pretty_json, #to_s, #to_wkt, #type
Constructor Details
#initialize(input) ⇒ Point
Returns a new instance of Point.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/carto_json/point.rb', line 9 def initialize(input) raise InputError, 'cannot create a shape with an array' if input.is_a?(Array) if input[LAT].nil? || input[LNG].nil? raise InputError, "#{LAT} and #{LNG} are required to instantiate a point" end input[LAT] = input[LAT].to_f input[LNG] = input[LNG].to_f super input unless (-90..90).include? input[LAT] raise InputError, "latitude must be between -90 and 90, \"#{input[LAT]}\" was provided" end unless (-180..180).include? input[LNG] raise InputError, "longitude must be between -180 and 180, \"#{input[LNG]}\" was provided" end end |
Instance Method Details
#==(point) ⇒ Object
41 42 43 |
# File 'lib/carto_json/point.rb', line 41 def ==(point) send(LAT) == point.send(LAT) && send(LNG) == point.send(LNG) end |