class VehicleCodingPh::Checker

Public Class Methods

call(plate_no, datetime = Time.now) click to toggle source
# File lib/vehicle_coding_ph/checker.rb, line 4
def self.call(plate_no, datetime = Time.now)
  return allowed_anywhere if weekend?(datetime)
  return allowed_anywhere if not coding?(plate_no, datetime)

  allowed_areas     = []
  not_allowed_areas = []
  hour_of_the_day   = datetime.hour

  VehicleCodingPh::AREA_TO_HOUR_MAPPING.each do |area, hours|
    if hours.empty? || !hours.include?(hour_of_the_day)
      allowed_areas << area
    else
      not_allowed_areas << area
    end
  end

  Response.new(true, allowed_areas, not_allowed_areas)
end

Private Class Methods

allowed_anywhere() click to toggle source
# File lib/vehicle_coding_ph/checker.rb, line 39
def self.allowed_anywhere
  Response.new(false, [:anywhere], [])
end
coding?(plate, datetime) click to toggle source
# File lib/vehicle_coding_ph/checker.rb, line 28
def self.coding?(plate, datetime)
  last_digit = plate[-1]
  day_today = Date::DAYNAMES[datetime.wday]

  mapping = VehicleCodingPh.coding_scheme.
    find { |mapping| mapping[:day] == day_today }

  mapping[:plates].include?(last_digit)
end
weekend?(datetime) click to toggle source
# File lib/vehicle_coding_ph/checker.rb, line 23
def self.weekend?(datetime)
  datetime.saturday? || datetime.sunday?
end