class RoutificApi::Location
This class represents a location in the network
Attributes
lat[RW]
lng[RW]
name[RW]
Public Class Methods
new(params)
click to toggle source
Constructor
Required arguments in params: lat: Latitude of this location lng: Longitude of this location
Optional arguments in params: name: Name of this location
# File lib/routific/location.rb, line 14 def initialize(params) # Validates the parameters provided validate(params) @lat = params["lat"] @lng = params["lng"] @name = params["name"] end
Public Instance Methods
==(another_location)
click to toggle source
# File lib/routific/location.rb, line 23 def ==(another_location) self.name == another_location.name && self.lat == another_location.lat && self.lng == another_location.lng end
as_json(options = nil)
click to toggle source
Returns the JSON representation of this object def to_json
(options = nil)
# File lib/routific/location.rb, line 35 def as_json(options = nil) jsonData = {} jsonData["name"] = self.name if self.name jsonData["lat"] = self.lat jsonData["lng"] = self.lng jsonData end
to_json(options = nil)
click to toggle source
# File lib/routific/location.rb, line 29 def to_json(options = nil) as_json(options).to_json end
Private Instance Methods
validate(params)
click to toggle source
Validates the parameters being provided Raises an ArgumentError if any of the required parameters is not provided. Required parameters are: latitude and longitude
# File lib/routific/location.rb, line 48 def validate(params) if(params["lat"].nil? || params["lng"].nil?) raise ArgumentError, "'lat' and 'lng' parameters must be provided" end end