thai_geodata 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 +7 -0
- data/.gitignore +56 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/README.md +92 -0
- data/Rakefile +9 -0
- data/lib/thai_geodata/data/districts.json +7426 -0
- data/lib/thai_geodata/data/provinces.json +464 -0
- data/lib/thai_geodata/data/subdistricts.json +66926 -0
- data/lib/thai_geodata/version.rb +5 -0
- data/lib/thai_geodata.rb +26 -0
- data/test/test_thai_geodata.rb +10 -0
- data/thai_geodata.gemspec +20 -0
- metadata +56 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a834e0b3da9844bd334e183cf4b49fc2bbf8a64a10eb57c6534431dca99b4232
|
|
4
|
+
data.tar.gz: 4b5423f51b064bcb9280054ee8f81e659f0815081deef33c758b302a41d3680b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6fe2aedf5751f62e91882cf2200e7f2ca0aceab6c8cb5a71c2e3d1fab10fb23ea8f999a47467bd42cbce539e9ee5c2db7db01158405db967e5553520ea9b7fbd
|
|
7
|
+
data.tar.gz: 0dc0743834208419ac619b3bb1960a89f7cc5f04494bcd20685f1ab222f79cc6573d52ea94d1f9ac9369d1758c52ee9cd903701b0de9309445473b1aa727e61e
|
data/.gitignore
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
/.config
|
|
4
|
+
/coverage/
|
|
5
|
+
/InstalledFiles
|
|
6
|
+
/pkg/
|
|
7
|
+
/spec/reports/
|
|
8
|
+
/spec/examples.txt
|
|
9
|
+
/test/tmp/
|
|
10
|
+
/test/version_tmp/
|
|
11
|
+
/tmp/
|
|
12
|
+
|
|
13
|
+
# Used by dotenv library to load environment variables.
|
|
14
|
+
# .env
|
|
15
|
+
|
|
16
|
+
# Ignore Byebug command history file.
|
|
17
|
+
.byebug_history
|
|
18
|
+
|
|
19
|
+
## Specific to RubyMotion:
|
|
20
|
+
.dat*
|
|
21
|
+
.repl_history
|
|
22
|
+
build/
|
|
23
|
+
*.bridgesupport
|
|
24
|
+
build-iPhoneOS/
|
|
25
|
+
build-iPhoneSimulator/
|
|
26
|
+
|
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
|
28
|
+
#
|
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
|
32
|
+
#
|
|
33
|
+
# vendor/Pods/
|
|
34
|
+
|
|
35
|
+
## Documentation cache and generated files:
|
|
36
|
+
/.yardoc/
|
|
37
|
+
/_yardoc/
|
|
38
|
+
/doc/
|
|
39
|
+
/rdoc/
|
|
40
|
+
|
|
41
|
+
## Environment normalization:
|
|
42
|
+
/.bundle/
|
|
43
|
+
/vendor/bundle
|
|
44
|
+
/lib/bundler/man/
|
|
45
|
+
|
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
48
|
+
Gemfile.lock
|
|
49
|
+
.ruby-version
|
|
50
|
+
.ruby-gemset
|
|
51
|
+
|
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
53
|
+
.rvmrc
|
|
54
|
+
|
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
|
56
|
+
# .rubocop-https?--*
|
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Chayut Orapinpatipat
|
|
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,92 @@
|
|
|
1
|
+
# ThaiGeodata
|
|
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.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
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
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Add this line to your application’s `Gemfile`:
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
gem "thai_geodata"
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Then execute:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
bundle install
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or install directly:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
gem install thai_geodata
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
require "thai_geodata"
|
|
36
|
+
|
|
37
|
+
# List all provinces
|
|
38
|
+
ThaiGeodata.provinces.each do |prov|
|
|
39
|
+
puts "#{prov["provinceCode"]}: #{prov["provinceNameTh"]} (#{prov["provinceNameEn"]})"
|
|
40
|
+
end
|
|
41
|
+
# => 10: กรุงเทพมหานคร (Bangkok)
|
|
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
|
+
# => พร้าว, ท่าตอน, …
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## API Reference
|
|
67
|
+
|
|
68
|
+
* `ThaiGeodata.provinces` → Array of province hashes
|
|
69
|
+
* `ThaiGeodata.districts` → Array of district hashes
|
|
70
|
+
* `ThaiGeodata.subdistricts` → Array of subdistrict hashes
|
|
71
|
+
|
|
72
|
+
*All methods memoize their data on first call.*
|
|
73
|
+
|
|
74
|
+
## Data Source & Attribution
|
|
75
|
+
|
|
76
|
+
Geographical data licensed under MIT and maintained by the [Thailand Geography JSON](https://github.com/thailand-geography-data/thailand-geography-json) project.
|
|
77
|
+
|
|
78
|
+
> **License**: MIT — see [LICENSE.txt](LICENSE.txt) for full text.
|
|
79
|
+
|
|
80
|
+
## Contributing
|
|
81
|
+
|
|
82
|
+
1. Fork the repo
|
|
83
|
+
2. Create or update JSON files under `lib/thai_geodata/data/`
|
|
84
|
+
3. Write tests in `test/` and ensure `rake test` passes
|
|
85
|
+
4. Submit a PR with a clear description of changes
|
|
86
|
+
|
|
87
|
+
Please follow the existing code style and include tests for any new features or bugfixes.
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
© 2025 Chayut Orapinpatipat
|
|
92
|
+
Released under the MIT License. See [LICENSE.txt](LICENSE.txt) for details.
|