Class: VehicleCodingPh::Checker

Inherits:
Object
  • Object
show all
Defined in:
lib/vehicle_coding_ph/checker.rb

Class Method Summary collapse

Class Method Details

.call(plate_no, datetime = Time.now) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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