Class: QrForge::Payloads::Geo
- Inherits:
-
Object
- Object
- QrForge::Payloads::Geo
- Defined in:
- lib/qr_forge/payloads/geo.rb
Overview
Represents a geo lat/long payload
Instance Method Summary collapse
-
#initialize(latitude:, longitude:) ⇒ Geo
constructor
A new instance of Geo.
- #to_s ⇒ Object
-
#validate! ⇒ Object
Validates that the passed latitude and longitude are within valid ranges.
Constructor Details
#initialize(latitude:, longitude:) ⇒ Geo
Returns a new instance of Geo.
9 10 11 12 |
# File 'lib/qr_forge/payloads/geo.rb', line 9 def initialize(latitude:, longitude:) @latitude = latitude @longitude = longitude end |
Instance Method Details
#to_s ⇒ Object
14 15 16 |
# File 'lib/qr_forge/payloads/geo.rb', line 14 def to_s "geo:#{@latitude},#{@longitude}" end |
#validate! ⇒ Object
Validates that the passed latitude and longitude are within valid ranges.
20 21 22 23 24 |
# File 'lib/qr_forge/payloads/geo.rb', line 20 def validate! return if (-90..90).cover?(@latitude.to_f) && (-180..180).cover?(@longitude.to_f) raise PayloadValidationError, "Latitude or longitude out of range" end |