vehicle_coding_ph 0.2.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3cc0616b90c86b72c8cca57b1c565f60f06d8d8516969eb87c4ce47c21999556
4
- data.tar.gz: 0d4b7e37ae873cafa2f5a09bc1991f7b3e016c5579fff48ad8ff2418f401aa68
3
+ metadata.gz: ce3082de37eaf01f116650c3f08c65c42a5ff17ab5ccbbb0eb2063f4e7cbb408
4
+ data.tar.gz: a90fcd77170c3698f7bbf67233fa59ce5d1ca31d69fc4e3d25b5fe069052cc31
5
5
  SHA512:
6
- metadata.gz: 2ad16c1745314249a63a32370c8d52d46ce287e1fbd923c6af46c0d44d897ef50c7380a098f8c93fbcb0163120b6ce27e8a807e2b7966d5fe134cd398ff1bb07
7
- data.tar.gz: 67b1f47d2469f4a620e2aef2c64958d0f7113e4cad2ba0650a3045cb3f966a80a84c59a4475dd8d8140462916bc6df446ece9df856ce9efa609bd4147dd6bf63
6
+ metadata.gz: 0c04dafd33bd52e31b21c145319eb2b0b766463af48e10aa7125171c7683cbd7004a92d9099a8a1d6fbedd16320de7fa074e5d6e46c52d5e80181523ae9c0c6e
7
+ data.tar.gz: 76e02fd654d3ab61e9eaada8f0fed98c17716c032616071552976376961f7e6aa98168df701a3c73150a6a920dde5567c9637791353a775adc2bdd2aa62ede89
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vehicle_coding_ph (0.2.0)
4
+ vehicle_coding_ph (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -4,6 +4,13 @@
4
4
 
5
5
  Helps you figure out if your car is legally okay to drive on a given date in the Philippines.
6
6
 
7
+ ## Version 1.0 roadmap
8
+
9
+ - [x] Response object
10
+ - [x] Consider window hours
11
+ - [ ] Helpful return messages for the Gem users e.g. "areas you're allowed or
12
+ not allowed to go to" because areas have particular coding scheme applied
13
+
7
14
  ## Installation
8
15
 
9
16
  Add this line to your application's Gemfile:
@@ -23,11 +30,16 @@ Or install it yourself as:
23
30
  ## Usage
24
31
 
25
32
  ```ruby
26
- # Returns true if allowed to drive today; otherwise it's false
27
- VehicleCodingPh::Checker.(
33
+ result = VehicleCodingPh::Checker.(
28
34
  plate_number_of_your_vehicle,
29
- date # if not passed, defaults to date today
35
+ datetime # if not passed, defaults to datetime today
30
36
  )
37
+
38
+ # result is a hash that has the ff. data structure
39
+ {
40
+ coding: boolean,
41
+ allowed_areas: [] # array of areas in Metro Manila
42
+ }
31
43
  ```
32
44
 
33
45
  ## Development
@@ -1,22 +1,47 @@
1
1
  module VehicleCodingPh
2
2
  class Checker
3
3
 
4
- def self.call(plate_no, date = Date.today)
5
- return true if weekend?(date)
4
+ def self.call(plate_no, datetime = Time.now)
5
+ return allowed_anywhere if weekend?(datetime)
6
+ return allowed_anywhere if not coding?(plate_no, datetime)
6
7
 
7
- last_digit = plate_no[-1]
8
- day_today = Date::DAYNAMES[date.cwday]
8
+ hour_of_the_day = datetime.hour
9
+
10
+ allowed_areas = VehicleCodingPh::AREA_TO_HOUR_MAPPING.reduce([]) do |hash, mapping|
11
+ hash ||= []
12
+ area = mapping[0]
13
+ coding_hours = mapping[1]
14
+
15
+ if coding_hours.empty? || !coding_hours.include?(hour_of_the_day)
16
+ hash << area
17
+ end
18
+
19
+ hash
20
+ end
21
+
22
+ Response.new(true, allowed_areas)
23
+ end
24
+
25
+ def self.weekend?(datetime)
26
+ datetime.saturday? || datetime.sunday?
27
+ end
28
+ private_class_method :weekend?
29
+
30
+ def self.coding?(plate, datetime)
31
+ last_digit = plate[-1]
32
+ day_today = Date::DAYNAMES[datetime.wday]
9
33
 
10
34
  mapping = VehicleCodingPh::PLATE_TO_DAY_MAPPING.
11
35
  select { |day, digits| day == day_today }
12
36
 
13
- !mapping[day_today].include?(last_digit)
37
+ mapping[day_today].include?(last_digit)
14
38
  end
39
+ private_class_method :coding?
15
40
 
16
- def self.weekend?(date)
17
- date.saturday? || date.sunday?
41
+ def self.allowed_anywhere
42
+ Response.new(false, [:anywhere])
18
43
  end
19
- private_class_method :weekend?
44
+ private_class_method :allowed_anywhere
20
45
 
21
46
  end
22
47
  end
@@ -0,0 +1,12 @@
1
+ module VehicleCodingPh
2
+ class Response
3
+
4
+ attr_reader :coding, :allowed_areas
5
+
6
+ def initialize(coding, areas)
7
+ @coding = coding
8
+ @allowed_areas = areas
9
+ end
10
+
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module VehicleCodingPh
2
- VERSION = "0.2.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -1,6 +1,7 @@
1
1
  require "date"
2
2
  require "vehicle_coding_ph/version"
3
3
  require "vehicle_coding_ph/checker"
4
+ require "vehicle_coding_ph/response"
4
5
 
5
6
  module VehicleCodingPh
6
7
  class Error < StandardError; end
@@ -14,4 +15,24 @@ module VehicleCodingPh
14
15
  "Saturday" => [],
15
16
  "Sunday" => [],
16
17
  }
18
+
19
+ AREA_TO_HOUR_MAPPING = {
20
+ "Marikina" => [],
21
+ "Muntinlupa" => [],
22
+ "Taguig" => [],
23
+ "Pasig" => [7, 8, 9, 16, 17, 18, 19],
24
+ "Makati" => [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
25
+ "Mandaluyong" => [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
26
+ "Pasay" => [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
27
+ "Las Pinas" => [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
28
+ "Paranaque" => [7, 8, 9, 16, 17, 18, 19],
29
+ "Caloocan" => [7, 8, 9, 10, 16, 17, 18, 19],
30
+ "Quezon City" => [7, 8, 9, 10, 16, 17, 18, 19],
31
+ "Valenzuela" => [7, 8, 9, 10, 16, 17, 18, 19],
32
+ "Malabon" => [7, 8, 9, 10, 16, 17, 18, 19],
33
+ "San Juan" => [7, 8, 9, 10, 16, 17, 18, 19],
34
+ "Navotas" => [7, 8, 9, 10, 16, 17, 18, 19],
35
+ "Manila" => [7, 8, 9, 10, 16, 17, 18, 19],
36
+ "Pateros" => [7, 8, 9, 10, 16, 17, 18, 19],
37
+ }
17
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vehicle_coding_ph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Chavez
@@ -100,6 +100,7 @@ files:
100
100
  - bin/setup
101
101
  - lib/vehicle_coding_ph.rb
102
102
  - lib/vehicle_coding_ph/checker.rb
103
+ - lib/vehicle_coding_ph/response.rb
103
104
  - lib/vehicle_coding_ph/version.rb
104
105
  - vehicle_coding_ph.gemspec
105
106
  homepage: http://www.localhost.com