class RoutificApi::Visit
This class represents a location to be visited
Attributes
demand[R]
duration[R]
end[R]
id[R]
location[R]
priority[R]
start[R]
time_windows[R]
type[R]
Public Class Methods
new(id, params = {})
click to toggle source
Constructor
Optional arguments in params: start: the earliest time for this visit. Default value is 00:00, if not specified. end: the latest time for this visit. Default value is 23:59, if not specified. duration: the length of this visit in minutes demand: the capacity that this visit requires location: the location of the visit. Instance of Location
# File lib/routific/visit.rb, line 15 def initialize(id, params = {}) validate(params) @id = id @start = params["start"] @end = params["end"] @duration = params["duration"] @demand = params["demand"] @location = RoutificApi::Location.new(params["location"]) @priority = params["priority"] @type = params["type"] if params["time_windows"] @time_windows = params["time_windows"].map{ |tw| TimeWindow.new(tw) } end end
Public Instance Methods
as_json(options = nil)
click to toggle source
Returns the JSON representation of this object def to_json
(options = nil)
# File lib/routific/visit.rb, line 36 def as_json(options = nil) json_data = {} json_data["start"] = self.start if self.start json_data["end"] = self.end if self.end json_data["duration"] = self.duration if self.duration json_data["demand"] = self.demand if self.demand json_data["location"] = self.location.as_json json_data["priority"] = self.priority if self.priority json_data["type"] = self.type if self.type if self.time_windows json_data["time_windows"] = self.time_windows.map{ |tw| tw.as_json } end json_data end
to_json(options)
click to toggle source
# File lib/routific/visit.rb, line 30 def to_json(options) 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: location
# File lib/routific/visit.rb, line 56 def validate(params) if params["location"].nil? raise ArgumentError, "'location' parameter must be provided" end end