psgc-rb 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1d1fd4a6936426a2a2efc694827ffd4d5fd0d33e13a8933ff5df64626edfb1ab
4
+ data.tar.gz: 552c45ca68904de0614b5d474ba1e055e4b3ef4139b80d6ecad0314de6b97a3c
5
+ SHA512:
6
+ metadata.gz: e4e8fd85a964fefa515233771a7551fe3dbd5070ab583aa9d8e45caefd76d084816e5fa46d6f0316c77485ae2da9b3dc5ff77b5594ac982d1d8692e5c74bbd7e
7
+ data.tar.gz: 7734822468ff709b6b093162220773ce207619ac5453481c4b58a9abeab4e2a555b75ea03533980811a638f7e99570d9e66d6f02ffe27622ac155da14bab98e8
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,19 @@
1
+ # Contributing
2
+
3
+ Contributions are welcome! Please follow these steps:
4
+
5
+ 1. Fork the repo
6
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
7
+ 3. Make your changes
8
+ 4. Run tests (`rake test`)
9
+ 5. Commit your changes (`git commit -m 'Add amazing feature'`)
10
+ 6. Push to the branch (`git push origin feature/amazing-feature`)
11
+ 7. Open a Pull Request
12
+
13
+ ## Data Updates
14
+
15
+ When PSA releases new PSGC data:
16
+
17
+ 1. Download the Excel file from https://psa.gov.ph/classification/psgc/
18
+ 2. Run `rake "data:parse[data/PSGC-Filename.xlsx]"`
19
+ 3. Commit the updated JSON files
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Al Kevin Tan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Psgc
2
+
3
+ A Ruby gem providing up-to-date Philippine geographic data from the PSA (Philippine Statistics Authority). Includes Philippine Standard Geographic Codes (PSGC) for regions, provinces, cities/municipalities, and barangays.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ gem install psgc-rb
9
+ ```
10
+
11
+ Or add to Gemfile:
12
+
13
+ ```ruby
14
+ gem "psgc-rb"
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```ruby
20
+ require "psgc"
21
+
22
+ # Get all regions
23
+ Psgc.regions
24
+ # => [{:code=>"1300000000", :name=>"National Capital Region (NCR)"}, ...]
25
+
26
+ # Get all provinces
27
+ Psgc.provinces
28
+ # => [{:code=>"1400100000", :name=>"Abra", :region_code=>"14"}, ...]
29
+
30
+ # Get all cities and municipalities
31
+ Psgc.cities_municipalities
32
+ # => [{:code=>"1400101000", :name=>"Bangued", :province_code=>"1400"}, ...]
33
+
34
+ # Get all barangays
35
+ Psgc.barangays
36
+ # => [{:code=>"1400101001", :name=>"Bagtayan", :city_municipality_code=>"1400101000"}, ...]
37
+ ```
38
+
39
+ ## Data Source
40
+
41
+ Data is sourced from the PSA PSGC Publication Datafile, released quarterly.
42
+ - URL: https://psa.gov.ph/classification/psgc/
43
+ - Current data: 1Q 2026
44
+
45
+ To update data:
46
+ 1. Download the latest Excel file from PSA
47
+ 2. Run `rake "data:parse[path/to/file.xlsx]"`
48
+ 3. Commit the updated JSON files
49
+
50
+ ## Development
51
+
52
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the MIT License.
data/Rakefile ADDED
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "json"
5
+ require "rake/testtask"
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << "test"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
13
+
14
+ namespace :data do
15
+ PSA_URL = "https://psa.gov.ph/classification/psgc/"
16
+
17
+ desc "Fetch latest PSGC data from PSA"
18
+ task :fetch do
19
+ puts "Fetching PSGC data from #{PSA_URL}"
20
+ puts "Note: Manual download required - PSA provides Excel files"
21
+ puts "Download: #{PSA_URL}"
22
+ end
23
+
24
+ desc "Parse PSGC Excel file and generate JSON fixtures"
25
+ task :parse, [:file] do |_t, args|
26
+ file = args[:file] || "data/PSGC-1Q-2026-Publication-Datafile.xlsx"
27
+ unless File.exist?(file)
28
+ abort "Excel file not found: #{file}. Run 'rake data:fetch' to download."
29
+ end
30
+
31
+ puts "Parsing #{file}..."
32
+ puts "(Using Python openpyxl)"
33
+
34
+ parse_with_python(file)
35
+
36
+ puts "Done."
37
+ end
38
+
39
+ def parse_with_python(file)
40
+ script = <<~PYTHON
41
+ import openpyxl
42
+ import json
43
+ import sys
44
+
45
+ wb = openpyxl.load_workbook(sys.argv[1])
46
+ ws = wb["PSGC"]
47
+
48
+ regions = []
49
+ provinces = []
50
+ cities_municipalities = []
51
+ barangays = []
52
+
53
+ for row in ws.iter_rows(min_row=2, values_only=True):
54
+ code = row[0]
55
+ name = row[1]
56
+ level = row[3]
57
+ if not code or not name or not level:
58
+ continue
59
+
60
+ code = str(code).strip()
61
+ name = str(name).strip()
62
+
63
+ entry = {"code": code, "name": name}
64
+
65
+ if level == "Reg":
66
+ regions.append(entry)
67
+ elif level == "Prov":
68
+ entry["region_code"] = code[:2]
69
+ provinces.append(entry)
70
+ elif level in ("City", "Mun", "SubMun"):
71
+ entry["province_code"] = code[:4]
72
+ cities_municipalities.append(entry)
73
+ elif level == "Bgy":
74
+ entry["city_municipality_code"] = code[:6]
75
+ barangays.append(entry)
76
+
77
+ with open("data/regions.json", "w") as f:
78
+ json.dump(regions, f, indent=2)
79
+ with open("data/provinces.json", "w") as f:
80
+ json.dump(provinces, f, indent=2)
81
+ with open("data/cities_municipalities.json", "w") as f:
82
+ json.dump(cities_municipalities, f, indent=2)
83
+ with open("data/barangays.json", "w") as f:
84
+ json.dump(barangays, f, indent=2)
85
+
86
+ print(f"Generated {len(regions)} regions, {len(provinces)} provinces, {len(cities_municipalities)} cities/municipalities, {len(barangays)} barangays")
87
+ PYTHON
88
+
89
+ py_pid = spawn("python3", "-c", script, file)
90
+ _, status = Process.wait2(py_pid)
91
+ raise "Python parsing failed" unless status.success?
92
+ end
93
+ end
94
+
95
+ desc "Update PSGC data (fetch + parse)"
96
+ task update: ["data:fetch", "data:parse"]