class RoutificApi::Break

This class represent a vehicle break

Constants

REQUIRED_PARAMS

Attributes

in_transit[R]

Public Class Methods

new(params) click to toggle source

Constructor

Required arguments in params: id: unique identifier for the break (e.g. 'lunch-break') start: start time of the break (e.g. '12:00') end: end time of the break (e.g. '12:30')

Optional argument in params: in_transit: whether the vehicle can be in movement during the break (e.g. true). The default value is false.

# File lib/routific/break.rb, line 18
def initialize(params)
  validate(params)

  @id = params["id"]
  @start = params["start"]
  @end = params["end"]
  @in_transit = params["in_transit"] unless params["in_transit"].nil?
end

Public Instance Methods

==(another_break) click to toggle source
# File lib/routific/break.rb, line 27
def ==(another_break)
  self.id == another_break.id &&
    self.start == another_break.start &&
    self.end == another_break.end &&
    self.in_transit == another_break.in_transit
end
as_json(options = nil) click to toggle source
# File lib/routific/break.rb, line 38
def as_json(options = nil)
  jsonData = {}
  jsonData["id"] = self.id
  jsonData["start"] = self.start
  jsonData["end"] = self.end
  jsonData["in_transit"] = self.in_transit unless self.in_transit.nil?

  jsonData
end
to_json(options = nil) click to toggle source
# File lib/routific/break.rb, line 34
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.

# File lib/routific/break.rb, line 51
def validate(params)
  REQUIRED_PARAMS.each do |param|
    if params[param].nil?
      raise ArgumentError, "'#{param}' parameter must be provided in break"
    end
  end
end