thai_geodata 0.1.0 → 0.2.1
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 +4 -4
- data/README.md +67 -44
- data/lib/thai_geodata/data/geography.json +96670 -0
- data/lib/thai_geodata/version.rb +1 -1
- data/lib/thai_geodata.rb +94 -13
- data/test/test_thai_geodata.rb +55 -2
- data/thai_geodata.gemspec +6 -3
- metadata +22 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a9a8263021e1dc2a4c6f329638cf8a4ffe48c4a6d3013b21aa63f943b346dfd1
|
|
4
|
+
data.tar.gz: '09c46f0d5bc7ee7fcc4caea9cb0fe0e23a0b77f968bb8519a487241f7c0c6fb6'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 59e5349ea8e774303984743e9a02b5eff1ee3313586737fb4b209b0c3f56b81d9c20b7a6cee8580029a7571246cbacbf7f1e8e044076d20b63f667b67a95f1ab
|
|
7
|
+
data.tar.gz: 8652400eb84543b888e4760b553476f243ac6b413d2eacbacd23940ff0ccaa957b6a8ae147548862d8dfbda19b87593e3b64e147eaf3471aff6dd42d9090e2f4
|
data/README.md
CHANGED
|
@@ -1,82 +1,107 @@
|
|
|
1
1
|
# ThaiGeodata
|
|
2
2
|
|
|
3
|
-
A lightweight Ruby gem providing Thailand’s official administrative geography data (provinces, districts, subdistricts) and postal codes in a Ruby-friendly API.
|
|
3
|
+
A lightweight Ruby gem providing Thailand’s official administrative geography data (provinces, districts, subdistricts) and postal codes in a Ruby-friendly API.
|
|
4
|
+
|
|
5
|
+
ไลบรารี Ruby ขนาดเล็กที่ให้ข้อมูลภูมิศาสตร์ของประเทศไทย (จังหวัด, อำเภอ, ตำบล) พร้อมรหัสไปรษณีย์ ผ่าน API ที่ใช้งานง่าย
|
|
6
|
+
|
|
4
7
|
|
|
5
8
|
## Features
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
- Fast lookups of provinces, districts, subdistricts, and postal codes
|
|
11
|
+
- Dual-language (Thai & English) support for data values
|
|
12
|
+
- Zero external dependencies (only stdlib JSON)
|
|
13
|
+
- Lazy–loaded and cached in memory
|
|
11
14
|
|
|
12
15
|
## Installation
|
|
13
16
|
|
|
14
|
-
Add
|
|
15
|
-
|
|
17
|
+
Add to your application’s `Gemfile`:
|
|
16
18
|
```ruby
|
|
17
19
|
gem "thai_geodata"
|
|
18
20
|
```
|
|
19
|
-
|
|
20
|
-
Then execute:
|
|
21
|
-
|
|
21
|
+
Then run:
|
|
22
22
|
```bash
|
|
23
23
|
bundle install
|
|
24
24
|
```
|
|
25
|
-
|
|
26
25
|
Or install directly:
|
|
27
|
-
|
|
28
26
|
```bash
|
|
29
27
|
gem install thai_geodata
|
|
30
28
|
```
|
|
31
29
|
|
|
32
|
-
## Usage
|
|
30
|
+
## Usage / การใช้งาน
|
|
33
31
|
|
|
34
32
|
```ruby
|
|
35
33
|
require "thai_geodata"
|
|
34
|
+
```
|
|
36
35
|
|
|
37
|
-
|
|
36
|
+
### List all provinces / แสดงรายชื่อจังหวัดทั้งหมด
|
|
37
|
+
```ruby
|
|
38
38
|
ThaiGeodata.provinces.each do |prov|
|
|
39
|
-
puts "#{prov[
|
|
39
|
+
puts "#{prov['provinceCode']}: #{prov['provinceNameTh']} (#{prov['provinceNameEn']})"
|
|
40
40
|
end
|
|
41
41
|
# => 10: กรุงเทพมหานคร (Bangkok)
|
|
42
42
|
# 50: เชียงใหม่ (Chiang Mai)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
puts
|
|
50
|
-
|
|
51
|
-
#
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Find by code or name / ค้นหาจังหวัดโดยรหัสหรือชื่อ
|
|
46
|
+
```ruby
|
|
47
|
+
# English or Thai name
|
|
48
|
+
prov = ThaiGeodata.find_province("Chiang Mai")
|
|
49
|
+
puts prov['provinceCode'] # => 50
|
|
50
|
+
|
|
51
|
+
# Thai name
|
|
52
|
+
prov_th = ThaiGeodata.find_province(10)
|
|
53
|
+
puts prov_th['provinceNameTh'] # => "กรุงเทพมหานคร"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Districts for a province / อำเภอทั้งหมดของจังหวัด
|
|
57
|
+
```ruby
|
|
58
|
+
dists = ThaiGeodata.districts_for_province(10)
|
|
59
|
+
puts dists.map { |d| d['districtNameTh'] }.join(", ")
|
|
60
|
+
# => พระนคร, ดุสิต, …
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Subdistricts for a district / ตำบลทั้งหมดของอำเภอ
|
|
64
|
+
```ruby
|
|
65
|
+
subs = ThaiGeodata.subdistricts_for_district("Phra Nakhon")
|
|
66
|
+
puts subs.map { |s| s['subdistrictNameTh'] }
|
|
67
|
+
# => พระบรมมหาราชวัง, วังบูรพาภิรมย์, …
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Postal code lookup / ค้นหารหัสไปรษณีย์
|
|
71
|
+
```ruby
|
|
72
|
+
pc = ThaiGeodata.postal_code_for_subdistrict("พระบรมมหาราชวัง")
|
|
73
|
+
puts pc # => 10200
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Combined geography records / ข้อมูลผสมจังหวัด-อำเภอ-ตำบล-รหัสไปรษณีย์
|
|
77
|
+
```ruby
|
|
78
|
+
results = ThaiGeodata.geography.select { |row| row['postalCode'] == 10200 }
|
|
79
|
+
results.each do |row|
|
|
80
|
+
puts "#{row['provinceNameTh']} > #{row['districtNameTh']} > #{row['subdistrictNameTh']} (#{row['postalCode']})"
|
|
81
|
+
end
|
|
82
|
+
# => กรุงเทพมหานคร > พระนคร > พระบรมมหาราชวัง (10200)
|
|
64
83
|
```
|
|
65
84
|
|
|
66
85
|
## API Reference
|
|
67
86
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
87
|
+
- `ThaiGeodata.provinces` → Array of province hashes
|
|
88
|
+
- `ThaiGeodata.districts` → Array of district hashes
|
|
89
|
+
- `ThaiGeodata.subdistricts` → Array of subdistrict hashes
|
|
90
|
+
- `ThaiGeodata.geography` → Combined array of all records
|
|
91
|
+
- `find_province(code_or_name)` → Single province hash or `nil`
|
|
92
|
+
- `find_district(code_or_name)` → Single district hash or `nil`
|
|
93
|
+
- `find_subdistrict(code_or_name)` → Single subdistrict hash or `nil`
|
|
94
|
+
- `districts_for_province(code_or_name)` → Array of districts
|
|
95
|
+
- `subdistricts_for_district(code_or_name)` → Array of subdistricts
|
|
96
|
+
- `postal_code_for_subdistrict(code_or_name)` → Integer or `nil`
|
|
97
|
+
- `location_path_for_subdistrict(code_or_name)` → `{province:, district:, subdistrict:}` or `nil`
|
|
71
98
|
|
|
72
|
-
|
|
99
|
+
_All methods memoize their data on first call._
|
|
73
100
|
|
|
74
101
|
## Data Source & Attribution
|
|
75
102
|
|
|
76
103
|
Geographical data licensed under MIT and maintained by the [Thailand Geography JSON](https://github.com/thailand-geography-data/thailand-geography-json) project.
|
|
77
104
|
|
|
78
|
-
> **License**: MIT — see [LICENSE.txt](LICENSE.txt) for full text.
|
|
79
|
-
|
|
80
105
|
## Contributing
|
|
81
106
|
|
|
82
107
|
1. Fork the repo
|
|
@@ -84,8 +109,6 @@ Geographical data licensed under MIT and maintained by the [Thailand Geography J
|
|
|
84
109
|
3. Write tests in `test/` and ensure `rake test` passes
|
|
85
110
|
4. Submit a PR with a clear description of changes
|
|
86
111
|
|
|
87
|
-
Please follow the existing code style and include tests for any new features or bugfixes.
|
|
88
|
-
|
|
89
112
|
## License
|
|
90
113
|
|
|
91
114
|
© 2025 Chayut Orapinpatipat
|