phil_locator 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop.yml +27 -0
  3. data/.github/workflows/update-copyright-years-in-license-file.yml +10 -0
  4. data/.gitignore +0 -1
  5. data/.rubocop.yml +0 -4
  6. data/CHANGELOG.md +41 -0
  7. data/Gemfile +5 -3
  8. data/Gemfile.lock +89 -0
  9. data/LICENSE +1 -1
  10. data/README.md +20 -9
  11. data/VERSION +1 -1
  12. data/app/models/phil_locator/barangay.rb +20 -14
  13. data/app/models/phil_locator/city.rb +5 -11
  14. data/app/models/phil_locator/district.rb +13 -0
  15. data/app/models/phil_locator/island_group.rb +8 -0
  16. data/app/models/phil_locator/municipality.rb +13 -0
  17. data/app/models/phil_locator/province.rb +9 -6
  18. data/app/models/phil_locator/region.rb +15 -5
  19. data/app/models/phil_locator/sub_municipality.rb +13 -0
  20. data/lib/datasets/json/barangays.json +1 -0
  21. data/lib/datasets/json/cities.json +1 -0
  22. data/lib/datasets/json/districts.json +1 -0
  23. data/lib/datasets/json/island_groups.json +1 -0
  24. data/lib/datasets/json/municipalities.json +1 -0
  25. data/lib/datasets/json/provinces.json +1 -0
  26. data/lib/datasets/json/regions.json +1 -0
  27. data/lib/datasets/json/sub_municipalities.json +1 -0
  28. data/lib/datasets/yaml/barangays.yml +378406 -0
  29. data/lib/datasets/yaml/cities.yml +1315 -0
  30. data/lib/datasets/yaml/districts.yml +33 -0
  31. data/lib/datasets/yaml/island_groups.yml +7 -0
  32. data/lib/datasets/yaml/municipalities.yml +13393 -0
  33. data/lib/datasets/yaml/provinces.yml +730 -0
  34. data/lib/datasets/yaml/regions.yml +137 -0
  35. data/lib/datasets/yaml/sub_municipalities.yml +113 -0
  36. data/lib/phil_locator/configuration.rb +1 -1
  37. data/lib/phil_locator.rb +2 -2
  38. data/phil_locator.gemspec +1 -1
  39. metadata +32 -13
  40. data/.codeclimate.yml +0 -33
  41. data/data/barangays.yml +0 -210146
  42. data/data/cities.yml +0 -8236
  43. data/data/provinces.yml +0 -441
  44. data/data/regions.yml +0 -86
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2afacfcf46e8fb8e86447b0070dc11040997719d295208ecea39728837e49f67
4
- data.tar.gz: 345d4046c2963b6147d24f931799196fd811139eeb08f10183204e948b8833c6
3
+ metadata.gz: 8c30061908794e2bb4cc7d73036f509ca97aa87f1a3ab1e869ef8e7d346ba3c8
4
+ data.tar.gz: d981ed1ec4118c495543e73130ff24088e3050e4dd5df7232980b7e26e753563
5
5
  SHA512:
6
- metadata.gz: 7b5bb5b14e94e486c0b1b0e494a066c91ff19fb761a7c6d3163a24c5bc5f707f03666391e82861a39b55236ed42a6e04dca8110a7c84cc88b7724ea7402b7abe
7
- data.tar.gz: f60bc55905e3b1fcc0ab0f75fc2185854df363c061129daeb7297c2580d013fea53f2ff65fb9978612a25629f43d3956352e38635b3c0f8039448adc77bddf5b
6
+ metadata.gz: ef3047b18073a0416bb2da98dbd2c5281e9548dd6e82360bd09211b021decb245d0dc127c907959082a77778f96d4d12a70071a2bea7bf919a25324bc71f72a0
7
+ data.tar.gz: 72aef4cda826b411a716b7d1df41abb512d12b5cf4f8229a6175c711f1309e3ad4c55310de121a82db7f0dfad21a6db5c4c6c0ae6f633c740576b8ababa719ae
@@ -0,0 +1,27 @@
1
+ name: RuboCop
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+
9
+ steps:
10
+ - uses: actions/checkout@v2
11
+ - name: Set up Ruby 2.7
12
+ uses: ruby/setup-ruby@v1
13
+ with:
14
+ ruby-version: 2.7
15
+ - name: Cache gems
16
+ uses: actions/cache@v1
17
+ with:
18
+ path: vendor/bundle
19
+ key: ${{ runner.os }}-rubocop-${{ hashFiles('**/Gemfile.lock') }}
20
+ restore-keys: |
21
+ ${{ runner.os }}-rubocop-
22
+ - name: Install gems
23
+ run: |
24
+ bundle config path vendor/bundle
25
+ bundle install --jobs 4 --retry 3
26
+ - name: Run RuboCop
27
+ run: bundle exec rubocop --parallel
@@ -0,0 +1,10 @@
1
+ name: Update copyright year(s) in license file
2
+
3
+ on:
4
+ schedule:
5
+ - cron: "0 0 1 * *"
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ update_license:
10
+ uses: tenshiAMD/.github/.github/workflows/update-copyright-years-in-license-file.yml@master
data/.gitignore CHANGED
@@ -4,4 +4,3 @@
4
4
  .rubocop-*
5
5
 
6
6
  *.gem
7
- Gemfile.lock
data/.rubocop.yml CHANGED
@@ -1,7 +1,3 @@
1
- require:
2
- - rubocop-performance
3
- - rubocop-rails
4
-
5
1
  inherit_from:
6
2
  - 'https://raw.githubusercontent.com/rails/rails/master/.rubocop.yml'
7
3
 
data/CHANGELOG.md ADDED
@@ -0,0 +1,41 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased](https://github.com/tenshiAMD/phil_locator/tree/HEAD)
4
+
5
+ [Full Changelog](https://github.com/tenshiAMD/phil_locator/compare/v1.3.0...HEAD)
6
+
7
+ ## [v1.3.0](https://github.com/tenshiAMD/phil_locator/tree/v1.3.0) (2023-11-10)
8
+
9
+ - Implement `island_groups`, `municipalities`, `districts` (Metro Manila Only), `sub_municipalities` (Metro Manila Only)
10
+ - Improve and fix model associations
11
+ - Set ruby version to `2.7`
12
+ - Fix `rubocop` issues
13
+
14
+ [Full Changelog](https://github.com/tenshiAMD/phil_locator/compare/v1.2.1...v1.3.0)
15
+
16
+ ## [v1.2.1](https://github.com/tenshiAMD/phil_locator/tree/v1.2.1) (2020-03-11)
17
+
18
+ - Fix `code` for `Region 5` in data
19
+
20
+ [Full Changelog](https://github.com/tenshiAMD/phil_locator/compare/v1.2.0...v1.2.1)
21
+
22
+ ## [v1.2.0](https://github.com/tenshiAMD/phil_locator/tree/v1.2.0) (2019-10-21)
23
+
24
+ - Implement `data_root_path` configuration
25
+ - Implement configuration via `configure` block
26
+
27
+ [Full Changelog](https://github.com/tenshiAMD/phil_locator/compare/v1.1.0...v1.2.0)
28
+
29
+ ## [v1.1.0](https://github.com/tenshiAMD/phil_locator/tree/v1.1.0) (2019-10-18)
30
+
31
+ - Update relations for `regions`, `cities`, and `provinces`
32
+ - Implement `barangays`
33
+
34
+ [Full Changelog](https://github.com/tenshiAMD/phil_locator/compare/v1.0.0.pre...v1.1.0)
35
+
36
+ ## [v1.0.0.pre](https://github.com/tenshiAMD/phil_locator/tree/v1.0.0.pre) (2019-10-17)
37
+
38
+ - Initial release
39
+
40
+ [Full Changelog](https://github.com/tenshiAMD/phil_locator/compare/71934c50b3182f605cd06d0ce539a265f50c4886...v1.0.0.pre)
41
+
data/Gemfile CHANGED
@@ -8,8 +8,10 @@ end
8
8
  gemspec
9
9
 
10
10
  group :development, :test do
11
- gem "rubocop", ">= 0.74.0", require: false
12
- gem "rubocop-junit-formatter"
11
+ gem "rubocop", ">= 1.25.1", require: false
12
+ gem "rubocop-minitest", require: false
13
+ gem "rubocop-packaging", require: false
13
14
  gem "rubocop-performance", require: false
14
- gem "rubocop-rails", "~> 2.0.1", require: false
15
+ gem "rubocop-rails", require: false
16
+ gem "rubocop-md", require: false
15
17
  end
data/Gemfile.lock ADDED
@@ -0,0 +1,89 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ phil_locator (1.3.0)
5
+ active_hash (~> 2.3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ active_hash (2.3.0)
11
+ activesupport (>= 5.0.0)
12
+ activesupport (7.1.1)
13
+ base64
14
+ bigdecimal
15
+ concurrent-ruby (~> 1.0, >= 1.0.2)
16
+ connection_pool (>= 2.2.5)
17
+ drb
18
+ i18n (>= 1.6, < 2)
19
+ minitest (>= 5.1)
20
+ mutex_m
21
+ tzinfo (~> 2.0)
22
+ ast (2.4.2)
23
+ base64 (0.1.1)
24
+ bigdecimal (3.1.4)
25
+ concurrent-ruby (1.2.2)
26
+ connection_pool (2.4.1)
27
+ drb (2.1.1)
28
+ ruby2_keywords
29
+ i18n (1.14.1)
30
+ concurrent-ruby (~> 1.0)
31
+ json (2.6.3)
32
+ language_server-protocol (3.17.0.3)
33
+ minitest (5.20.0)
34
+ mutex_m (0.1.2)
35
+ parallel (1.23.0)
36
+ parser (3.2.2.4)
37
+ ast (~> 2.4.1)
38
+ racc
39
+ racc (1.7.1)
40
+ rack (3.0.8)
41
+ rainbow (3.1.1)
42
+ regexp_parser (2.8.2)
43
+ rexml (3.2.6)
44
+ rubocop (1.57.2)
45
+ json (~> 2.3)
46
+ language_server-protocol (>= 3.17.0)
47
+ parallel (~> 1.10)
48
+ parser (>= 3.2.2.4)
49
+ rainbow (>= 2.2.2, < 4.0)
50
+ regexp_parser (>= 1.8, < 3.0)
51
+ rexml (>= 3.2.5, < 4.0)
52
+ rubocop-ast (>= 1.28.1, < 2.0)
53
+ ruby-progressbar (~> 1.7)
54
+ unicode-display_width (>= 2.4.0, < 3.0)
55
+ rubocop-ast (1.30.0)
56
+ parser (>= 3.2.1.0)
57
+ rubocop-md (1.2.1)
58
+ rubocop (>= 1.0)
59
+ rubocop-minitest (0.33.0)
60
+ rubocop (>= 1.39, < 2.0)
61
+ rubocop-packaging (0.5.2)
62
+ rubocop (>= 1.33, < 2.0)
63
+ rubocop-performance (1.19.1)
64
+ rubocop (>= 1.7.0, < 2.0)
65
+ rubocop-ast (>= 0.4.0)
66
+ rubocop-rails (2.22.1)
67
+ activesupport (>= 4.2.0)
68
+ rack (>= 1.1)
69
+ rubocop (>= 1.33.0, < 2.0)
70
+ ruby-progressbar (1.13.0)
71
+ ruby2_keywords (0.0.5)
72
+ tzinfo (2.0.6)
73
+ concurrent-ruby (~> 1.0)
74
+ unicode-display_width (2.5.0)
75
+
76
+ PLATFORMS
77
+ ruby
78
+
79
+ DEPENDENCIES
80
+ phil_locator!
81
+ rubocop (>= 1.25.1)
82
+ rubocop-md
83
+ rubocop-minitest
84
+ rubocop-packaging
85
+ rubocop-performance
86
+ rubocop-rails
87
+
88
+ BUNDLED WITH
89
+ 2.1.4
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019 Angel Aviel Domaoan
3
+ Copyright (c) 2019-2023 Angel Aviel Domaoan
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,24 +1,31 @@
1
1
  # Phil Locator
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/phil_locator.svg)](https://badge.fury.io/rb/phil_locator)
4
-
5
- ## Build Status
6
- [![Maintainability](https://api.codeclimate.com/v1/badges/9cc2694e0d4b21080edc/maintainability)](https://codeclimate.com/github/tenshiAMD/phil_locator/maintainability)
7
- [![Test Coverage](https://api.codeclimate.com/v1/badges/9cc2694e0d4b21080edc/test_coverage)](https://codeclimate.com/github/tenshiAMD/phil_locator/test_coverage)
4
+ [![Known Vulnerabilities](https://snyk.io/test/github/tenshiAMD/phil_locator/badge.svg?targetFile=Gemfile.lock)](https://snyk.io/test/github/tenshiAMD/phil_locator?targetFile=Gemfile.lock)
5
+ [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FtenshiAMD%2Fphil_locator.svg?type=shield&issueType=license)](https://app.fossa.com/projects/git%2Bgithub.com%2FtenshiAMD%2Fphil_locator?ref=badge_shield&issueType=license)
8
6
 
9
7
  ## Description
10
- Provides registry records for `regions`, `cities`, `provinces`, and `barangays` in the Philippines.
8
+ Provides registry records in the Philippines which the data came from PSA (PSGC).
9
+
10
+ - `regions`
11
+ - `cities`
12
+ - `provinces`
13
+ - `barangays`
14
+ - `island_group`
15
+ - `municipality`
16
+ - `districts` (Metro Manila Only)
17
+ - `sub_municipality` (Metro Manila Only)
11
18
 
12
19
  ## Installation
13
20
 
14
21
  In Gemfile:
15
22
  ```
16
- gem "phil_locator", "~> 1.2.0"
23
+ gem "phil_locator", "~> 1.3.0"
17
24
  ```
18
25
 
19
26
  Or, from the command line:
20
27
  ```
21
- gem install phil_locator -v "~> 1.2.0"
28
+ gem install phil_locator -v "~> 1.3.0"
22
29
  ```
23
30
 
24
31
  ## Usage
@@ -44,10 +51,14 @@ Create an initializer `phil_locator.rb` to configure the options, here's a sampl
44
51
  ```
45
52
  PhilLocator.configure do |config|
46
53
  # This overrides the default data directory
47
- config.data_root_path = Rails.root.join("data").to_s
54
+ config.data_root_path = Rails.root.join("datasets").to_s
48
55
  end
49
56
  ```
50
57
 
51
58
  ## Copyright
52
59
 
53
- Copyright (c) 2019 Angel Aviel Domaoan, released under the [MIT license](/LICENSE).
60
+ This project is released under the [MIT license](/LICENSE).
61
+
62
+
63
+ ## License
64
+ [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FtenshiAMD%2Fphil_locator.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FtenshiAMD%2Fphil_locator?ref=badge_large)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.1
1
+ 1.3.0
@@ -2,29 +2,35 @@ module PhilLocator
2
2
  class Barangay < ActiveYaml::Base
3
3
  include ActiveHash::Associations
4
4
 
5
- set_root_path self.module_parent.data_root_path
5
+ set_root_path module_parent.data_root_path(:yaml)
6
6
  set_filename "barangays"
7
7
 
8
- belongs_to :city, class_name: "PhilLocator::City", foreign_key: :city_code, primary_key: :code
8
+ belongs_to :province, class_name: "PhilLocator::Province",
9
+ foreign_key: :province_code, primary_key: :province_code
10
+ delegate :region, to: :province
9
11
 
10
- def cities
11
- PhilLocator::City.where(region_code: code.to_i.to_s)
12
- end
12
+ has_many :barangays, class_name: "PhilLocator::Barangay",
13
+ foreign_key: :province_code, primary_key: :province_code
13
14
 
14
- def province
15
- return if city.blank?
15
+ alias_attribute :psgcCode, :code
16
16
 
17
- city.province
17
+ def type
18
+ self[:urbanRural].upcase == "U" ? "urban" : "rural"
18
19
  end
19
20
 
20
- def psgcCode
21
- code.ljust(9, "0")
21
+ def method_missing(method_name, *args, &block)
22
+ case method_name.to_sym
23
+ when :city
24
+ PhilLocator::City.find_by(city_code: urbanRuralCode)
25
+ when :municipality
26
+ PhilLocator::Municipality.find_by(municipality_code: urbanRuralCode)
27
+ else
28
+ super
29
+ end
22
30
  end
23
31
 
24
- def region
25
- return if province.blank?
26
-
27
- province.region
32
+ def respond_to_missing?(_method_name, _include_private = false)
33
+ true
28
34
  end
29
35
  end
30
36
  end
@@ -2,19 +2,13 @@ module PhilLocator
2
2
  class City < ActiveYaml::Base
3
3
  include ActiveHash::Associations
4
4
 
5
- set_root_path self.module_parent.data_root_path
5
+ set_root_path module_parent.data_root_path(:yaml)
6
6
  set_filename "cities"
7
7
 
8
- belongs_to :province, class_name: "PhilLocator::Province", foreign_key: :province_code, primary_key: :code
8
+ belongs_to :province, class_name: "PhilLocator::Province",
9
+ foreign_key: :province_code, primary_key: :province_code
10
+ delegate :region, to: :province
9
11
 
10
- def psgcCode
11
- code.ljust(9, "0")
12
- end
13
-
14
- def region
15
- return if province.blank?
16
-
17
- province.region
18
- end
12
+ alias_attribute :psgcCode, :code
19
13
  end
20
14
  end
@@ -0,0 +1,13 @@
1
+ module PhilLocator
2
+ class District < ActiveYaml::Base
3
+ include ActiveHash::Associations
4
+
5
+ set_root_path module_parent.data_root_path(:yaml)
6
+ set_filename "districts"
7
+
8
+ has_many :sub_municipalities, class_name: "PhilLocator::SubMunicipality",
9
+ foreign_key: :district_code, primary_key: :district_code
10
+
11
+ alias_attribute :psgcCode, :code
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ module PhilLocator
2
+ class IslandGroup < ActiveYaml::Base
3
+ include ActiveHash::Associations
4
+
5
+ set_root_path module_parent.data_root_path(:yaml)
6
+ set_filename "island_groups"
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ module PhilLocator
2
+ class Municipality < ActiveYaml::Base
3
+ include ActiveHash::Associations
4
+
5
+ set_root_path module_parent.data_root_path(:yaml)
6
+ set_filename "municipalities"
7
+
8
+ belongs_to :province, class_name: "PhilLocator::Province", foreign_key: :province_code, primary_key: :province_code
9
+ delegate :region, to: :province
10
+
11
+ alias_attribute :psgcCode, :code
12
+ end
13
+ end
@@ -2,15 +2,18 @@ module PhilLocator
2
2
  class Province < ActiveYaml::Base
3
3
  include ActiveHash::Associations
4
4
 
5
- set_root_path self.module_parent.data_root_path
5
+ set_root_path module_parent.data_root_path(:yaml)
6
6
  set_filename "provinces"
7
7
 
8
- belongs_to :region, class_name: "PhilLocator::Region", foreign_key: :region_code, primary_key: :code
8
+ belongs_to :region, class_name: "PhilLocator::Region",
9
+ foreign_key: :region_code, primary_key: :region_code
9
10
 
10
- has_many :cities, class_name: "PhilLocator::City", foreign_key: :province_code, primary_key: :code
11
+ has_many :cities, class_name: "PhilLocator::City",
12
+ foreign_key: :province_code, primary_key: :province_code
11
13
 
12
- def psgcCode
13
- code.ljust(9, "0")
14
- end
14
+ has_many :barangays, class_name: "PhilLocator::Barangay",
15
+ foreign_key: :province_code, primary_key: :province_code
16
+
17
+ alias_attribute :psgcCode, :code
15
18
  end
16
19
  end
@@ -2,17 +2,27 @@ module PhilLocator
2
2
  class Region < ActiveYaml::Base
3
3
  include ActiveHash::Associations
4
4
 
5
- set_root_path self.module_parent.data_root_path
5
+ set_root_path module_parent.data_root_path(:yaml)
6
6
  set_filename "regions"
7
7
 
8
- has_many :provinces, class_name: "PhilLocator::Province", foreign_key: :region_code, primary_key: :code
8
+ has_many :provinces, class_name: "PhilLocator::Province", foreign_key: :region_code, primary_key: :region_code
9
+
10
+ alias_attribute :psgcCode, :code
11
+
12
+ def alias
13
+ self[:name].split("(").last.strip.gsub(/\(|\)/, "")
14
+ end
9
15
 
10
16
  def cities
11
- PhilLocator::City.where(region_code: code.to_i.to_s)
17
+ PhilLocator::City.where(province_code: provinces.map(&:province_code))
18
+ end
19
+
20
+ def municipalities
21
+ PhilLocator::Municipality.where(province_code: provinces.map(&:province_code))
12
22
  end
13
23
 
14
- def psgcCode
15
- code.ljust(9, "0")
24
+ def name
25
+ self[:name].split("(").first.delete("(").strip
16
26
  end
17
27
  end
18
28
  end
@@ -0,0 +1,13 @@
1
+ module PhilLocator
2
+ class SubMunicipality < ActiveYaml::Base
3
+ include ActiveHash::Associations
4
+
5
+ set_root_path module_parent.data_root_path(:yaml)
6
+ set_filename "sub_municipalities"
7
+
8
+ belongs_to :district, class_name: "PhilLocator::District",
9
+ foreign_key: :district_code, primary_key: :district_code
10
+
11
+ alias_attribute :psgcCode, :code
12
+ end
13
+ end