Class: QrForge::Payloads::Geo

Inherits:
Object
  • Object
show all
Defined in:
lib/qr_forge/payloads/geo.rb

Overview

Represents a geo lat/long payload

Examples:

return “geo:40.712776,-74.005974”


Instance Method Summary collapse

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_sObject



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