vehicle_coding_ph 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +15 -3
- data/lib/vehicle_coding_ph/checker.rb +33 -8
- data/lib/vehicle_coding_ph/response.rb +12 -0
- data/lib/vehicle_coding_ph/version.rb +1 -1
- data/lib/vehicle_coding_ph.rb +21 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce3082de37eaf01f116650c3f08c65c42a5ff17ab5ccbbb0eb2063f4e7cbb408
|
4
|
+
data.tar.gz: a90fcd77170c3698f7bbf67233fa59ce5d1ca31d69fc4e3d25b5fe069052cc31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c04dafd33bd52e31b21c145319eb2b0b766463af48e10aa7125171c7683cbd7004a92d9099a8a1d6fbedd16320de7fa074e5d6e46c52d5e80181523ae9c0c6e
|
7
|
+
data.tar.gz: 76e02fd654d3ab61e9eaada8f0fed98c17716c032616071552976376961f7e6aa98168df701a3c73150a6a920dde5567c9637791353a775adc2bdd2aa62ede89
|
data/Gemfile.lock
CHANGED
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
|
-
|
27
|
-
VehicleCodingPh::Checker.(
|
33
|
+
result = VehicleCodingPh::Checker.(
|
28
34
|
plate_number_of_your_vehicle,
|
29
|
-
|
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,
|
5
|
-
return
|
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
|
-
|
8
|
-
|
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
|
-
|
37
|
+
mapping[day_today].include?(last_digit)
|
14
38
|
end
|
39
|
+
private_class_method :coding?
|
15
40
|
|
16
|
-
def self.
|
17
|
-
|
41
|
+
def self.allowed_anywhere
|
42
|
+
Response.new(false, [:anywhere])
|
18
43
|
end
|
19
|
-
private_class_method :
|
44
|
+
private_class_method :allowed_anywhere
|
20
45
|
|
21
46
|
end
|
22
47
|
end
|
data/lib/vehicle_coding_ph.rb
CHANGED
@@ -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.
|
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
|