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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a834e0b3da9844bd334e183cf4b49fc2bbf8a64a10eb57c6534431dca99b4232
4
- data.tar.gz: 4b5423f51b064bcb9280054ee8f81e659f0815081deef33c758b302a41d3680b
3
+ metadata.gz: a9a8263021e1dc2a4c6f329638cf8a4ffe48c4a6d3013b21aa63f943b346dfd1
4
+ data.tar.gz: '09c46f0d5bc7ee7fcc4caea9cb0fe0e23a0b77f968bb8519a487241f7c0c6fb6'
5
5
  SHA512:
6
- metadata.gz: 6fe2aedf5751f62e91882cf2200e7f2ca0aceab6c8cb5a71c2e3d1fab10fb23ea8f999a47467bd42cbce539e9ee5c2db7db01158405db967e5553520ea9b7fbd
7
- data.tar.gz: 0dc0743834208419ac619b3bb1960a89f7cc5f04494bcd20685f1ab222f79cc6573d52ea94d1f9ac9369d1758c52ee9cd903701b0de9309445473b1aa727e61e
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. All data is sourced from the [Thailand Geography JSON](https://github.com/thailand-geography-data/thailand-geography-json) project under the MIT license.
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
- * 🔍 Fast lookups of provinces, districts, subdistricts, and postal codes
8
- * 🇹🇭 Full Thai & English names
9
- * 📦 Zero external dependencies (only stdlib JSON)
10
- * 🛠 Lazy–loaded and cached in memory
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 this line to your application’s `Gemfile`:
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
- # List all provinces
36
+ ### List all provinces / แสดงรายชื่อจังหวัดทั้งหมด
37
+ ```ruby
38
38
  ThaiGeodata.provinces.each do |prov|
39
- puts "#{prov["provinceCode"]}: #{prov["provinceNameTh"]} (#{prov["provinceNameEn"]})"
39
+ puts "#{prov['provinceCode']}: #{prov['provinceNameTh']} (#{prov['provinceNameEn']})"
40
40
  end
41
41
  # => 10: กรุงเทพมหานคร (Bangkok)
42
42
  # 50: เชียงใหม่ (Chiang Mai)
43
- # …
44
-
45
- # Find a specific province by Thai or English name
46
- tg = ThaiGeodata.provinces.find { |p|
47
- p["provinceNameTh"] == "เชียงใหม่" || p["provinceNameEn"].casecmp("Chiang Mai").zero?
48
- }
49
- puts tg["provinceCode"] # => 50
50
-
51
- # Get all districts in a given province
52
- districts_in_cm = ThaiGeodata.districts.select { |d|
53
- d["provinceCode"] == tg["provinceCode"]
54
- }
55
- puts districts_in_cm.map { |d| d["districtNameTh"] }.join(", ")
56
- # => เมืองเชียงใหม่, แม่ริม, สารภี,
57
-
58
- # List all subdistricts in a given district code
59
- subdistricts_in_district = ThaiGeodata.subdistricts.select { |s|
60
- s["districtCode"] == districts_in_cm.first["districtCode"]
61
- }
62
- puts subdistricts_in_district.map { |s| s["subdistrictNameTh"] }.join(", ")
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
- * `ThaiGeodata.provinces` → Array of province hashes
69
- * `ThaiGeodata.districts` → Array of district hashes
70
- * `ThaiGeodata.subdistricts` → Array of subdistrict hashes
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
- *All methods memoize their data on first call.*
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