nayyar 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 +10 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +158 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/data/.gitkeep +0 -0
- data/lib/data/districts.yml +223 -0
- data/lib/data/extract.rb +19 -0
- data/lib/data/locations.csv +1 -0
- data/lib/data/states.yml +61 -0
- data/lib/data/townships.yml +1240 -0
- data/lib/nayyar.rb +7 -0
- data/lib/nayyar/district.rb +122 -0
- data/lib/nayyar/state.rb +107 -0
- data/lib/nayyar/township.rb +119 -0
- data/lib/nayyar/version.rb +3 -0
- data/nayyar.gemspec +39 -0
- metadata +128 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 080fe4ea4cca3830776db05bc161573574ce2040
|
|
4
|
+
data.tar.gz: fefda208dc6000e1e6fb556e1b419410ca4180cc
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 19c22e4015599bdae5058bdb8a55e7de45d859c9aa5825779b6172b7f7b132a9278fd69a8e7a582af93d01f2c85664b472e955f7f879acaa4438921ed89e89de
|
|
7
|
+
data.tar.gz: 3812e732b7f5aaf96c19b0651010ce9a6d5a94e0d9000bc345007803fa9155e8c2aeb5c79e35e6887d6fcb74c27064ccadcf9c65b46a0df621eb2adf0e42c4e2
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 mmhan
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# Nayyar / နေရာ
|
|
2
|
+
[](https://travis-ci.org/mmhan/nayyar.png)
|
|
3
|
+
|
|
4
|
+
Nayyar is created with the intent of providing basic access to State/Regions, Districts or Townships of Myanmar, based on standards of Myanmar's country-wide census of 2014.
|
|
5
|
+
|
|
6
|
+
15 States are indexed by MIMU's pcode, ISO3166-2:MM and alpha3 codes used in plate numbers by transportation authority.
|
|
7
|
+
74 Districts and 413 Townships are indexed by MIMU's pcode.
|
|
8
|
+
|
|
9
|
+
The current version is `0.1.0` and it uses [Semantic Versioning](http://semver.org/)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Add this line to your application's Gemfile:
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
gem 'nayyar'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
And then execute:
|
|
20
|
+
|
|
21
|
+
$ bundle
|
|
22
|
+
|
|
23
|
+
Or install it yourself as:
|
|
24
|
+
|
|
25
|
+
$ gem install nayyar
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
### States
|
|
30
|
+
|
|
31
|
+
Find all states using
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
Nayyar::State.all
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Find states using MIMU's pcodes:
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
Nayyar::State.find_by_pcode("MMR013")
|
|
41
|
+
# => <Nayyar::State:0x007fd05cc79e60 @data={:iso=>"MM-06", :pcode=>"MMR013", :alpha3=>"YGN", :name=>"Yangon"}>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Find states using ISO3166-2:MM:
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
Nayyar::State.find_by_iso("MM-01")
|
|
48
|
+
# => #<Nayyar::State:0x007fd05cc7a040 @data={:iso=>"MM-01", :pcode=>"MMR005", :alpha3=>"SGG", :name=>"Sagaing"}>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
Find states using alpha3
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
Nayyar::State.find_by_alpha3("SHN")
|
|
56
|
+
# => #<Nayyar::State:0x007fd05cc79e38 @data={:iso=>"MM-17", :pcode=>"MMR222", :alpha3=>"SHN", :name=>"Shan"}>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Or you can use a generic finder with an index
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
Nayyar::State.find_by(pcode: "MMR013") #or iso: or alpha3:
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Use any of the `find_by` or `find_by_**index_name**` with a bang `!` to trigger `Nayyar::StateNotFound` error.
|
|
66
|
+
|
|
67
|
+
### Districts
|
|
68
|
+
|
|
69
|
+
Find all districts using
|
|
70
|
+
```ruby
|
|
71
|
+
Nayyar::District.all
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Find districts under a certain state using
|
|
75
|
+
```ruby
|
|
76
|
+
shan_state = Nayyar::State.find_by_alpha3("SHN")
|
|
77
|
+
# get an array of all districts under Shan state using
|
|
78
|
+
shan_state.districts
|
|
79
|
+
# or
|
|
80
|
+
Nayyar::District.of_state(shan_state)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Find a district using pcode
|
|
84
|
+
```ruby
|
|
85
|
+
Nayyar::District.find_by_pcode("MMR001D001")
|
|
86
|
+
# or
|
|
87
|
+
Nayyar::District.find_by(pcode:"MMR001D001")
|
|
88
|
+
|
|
89
|
+
# => #<Nayyar::District:0x007f9bf5361418 @data={:pcode=>"MMR001D001", :name=>"Myitkyina", :state=>"MMR001"}>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Find the state that a district belongs to using
|
|
93
|
+
```ruby
|
|
94
|
+
Nayyar::District.find_by(pcode:"MMR001D001").state
|
|
95
|
+
|
|
96
|
+
# => <Nayyar::State:0x007f9bf532fc60 @data={:iso=>"MM-11", :pcode=>"MMR001", :alpha3=>"KCN", :name=>"Kachin"}>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Use any of the `find_by` or `find_by_**index_name**` with a bang `!` to trigger `Nayyar::DistrictNotFound` error.
|
|
100
|
+
|
|
101
|
+
### Townships
|
|
102
|
+
|
|
103
|
+
Find all townships using
|
|
104
|
+
```ruby
|
|
105
|
+
Nayyar::Townships.all
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Find townships under a certain state using
|
|
109
|
+
```ruby
|
|
110
|
+
ygn_east = Nayyar::District.find_by_pcode "MMR013D002"
|
|
111
|
+
# get an array of all districts under Shan state using
|
|
112
|
+
ygn_east.townships
|
|
113
|
+
# or
|
|
114
|
+
Nayyar::Township.of_district(ygn_east)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Find a township using pcode
|
|
118
|
+
```ruby
|
|
119
|
+
Nayyar::Township.find_by_pcode("MMR013017")
|
|
120
|
+
# or
|
|
121
|
+
Nayyar::Township.find_by(pcode:"MMR013017")
|
|
122
|
+
|
|
123
|
+
# => #<Nayyar::Township:0x007fb8a5b605e8 @data={:pcode=>"MMR013017", :name=>"Botahtaung", :district=>"MMR013D002"}>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Find the district that a township belongs to using
|
|
127
|
+
```ruby
|
|
128
|
+
Nayyar::Township.find_by(pcode:"MMR013017").township
|
|
129
|
+
|
|
130
|
+
# => <Nayyar::District:0x007fb8a5ad14d8 @data={:pcode=>"MMR013D002", :name=>"Yangon (East)", :state=>"MMR013"}>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Use any of the `find_by` or `find_by_**index_name**` with a bang `!` to trigger `Nayyar::TownshipNotFound` error.
|
|
134
|
+
<!--
|
|
135
|
+
## Development
|
|
136
|
+
|
|
137
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
138
|
+
|
|
139
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
140
|
+
-->
|
|
141
|
+
|
|
142
|
+
## Goals
|
|
143
|
+
1. Make it work
|
|
144
|
+
- Create just enough API to allow creations of dropdowns/multiple-select options in HTML ✓
|
|
145
|
+
2. Make it right
|
|
146
|
+
- Remove duplicate/similar codes across the three main classes using metaprogramming
|
|
147
|
+
3. Make it fast
|
|
148
|
+
- Optimize memory footprint by refactoring the way data is stored/read/used
|
|
149
|
+
|
|
150
|
+
If you feel that I have missed out your use-case or if you wanna add other goals, objectives [submit an issue](https://github.com/mmhan/nayyar/issues/new) so that I can plan it in.
|
|
151
|
+
|
|
152
|
+
## Contributing
|
|
153
|
+
|
|
154
|
+
1. Fork it ( https://github.com/mmhan/nayyar/fork )
|
|
155
|
+
2. Create your feature branch (`git checkout -b feature/my-new-feature`)
|
|
156
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
157
|
+
4. Push to the branch (`git push origin feature/my-new-feature`)
|
|
158
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "nayyar"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/data/.gitkeep
ADDED
|
File without changes
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
---
|
|
2
|
+
- :pcode: MMR001D001
|
|
3
|
+
:name: Myitkyina
|
|
4
|
+
:state: MMR001
|
|
5
|
+
- :pcode: MMR001D002
|
|
6
|
+
:name: Mohnyin
|
|
7
|
+
:state: MMR001
|
|
8
|
+
- :pcode: MMR001D003
|
|
9
|
+
:name: Bhamo
|
|
10
|
+
:state: MMR001
|
|
11
|
+
- :pcode: MMR001D004
|
|
12
|
+
:name: Puta-O
|
|
13
|
+
:state: MMR001
|
|
14
|
+
- :pcode: MMR002D001
|
|
15
|
+
:name: Loikaw
|
|
16
|
+
:state: MMR002
|
|
17
|
+
- :pcode: MMR002D002
|
|
18
|
+
:name: Bawlake
|
|
19
|
+
:state: MMR002
|
|
20
|
+
- :pcode: MMR003D001
|
|
21
|
+
:name: Hpa-An
|
|
22
|
+
:state: MMR003
|
|
23
|
+
- :pcode: MMR003D004
|
|
24
|
+
:name: Hpapun
|
|
25
|
+
:state: MMR003
|
|
26
|
+
- :pcode: MMR003D002
|
|
27
|
+
:name: Myawaddy
|
|
28
|
+
:state: MMR003
|
|
29
|
+
- :pcode: MMR003D003
|
|
30
|
+
:name: Kawkareik
|
|
31
|
+
:state: MMR003
|
|
32
|
+
- :pcode: MMR004D003
|
|
33
|
+
:name: Hakha
|
|
34
|
+
:state: MMR004
|
|
35
|
+
- :pcode: MMR004D001
|
|
36
|
+
:name: Falam
|
|
37
|
+
:state: MMR004
|
|
38
|
+
- :pcode: MMR004D002
|
|
39
|
+
:name: Mindat
|
|
40
|
+
:state: MMR004
|
|
41
|
+
- :pcode: MMR005D001
|
|
42
|
+
:name: Sagaing
|
|
43
|
+
:state: MMR005
|
|
44
|
+
- :pcode: MMR005D002
|
|
45
|
+
:name: Shwebo
|
|
46
|
+
:state: MMR005
|
|
47
|
+
- :pcode: MMR005D003
|
|
48
|
+
:name: Monywa
|
|
49
|
+
:state: MMR005
|
|
50
|
+
- :pcode: MMR005D004
|
|
51
|
+
:name: Katha
|
|
52
|
+
:state: MMR005
|
|
53
|
+
- :pcode: MMR005D005
|
|
54
|
+
:name: Kale
|
|
55
|
+
:state: MMR005
|
|
56
|
+
- :pcode: MMR005D006
|
|
57
|
+
:name: Tamu
|
|
58
|
+
:state: MMR005
|
|
59
|
+
- :pcode: MMR005D007
|
|
60
|
+
:name: Mawlaik
|
|
61
|
+
:state: MMR005
|
|
62
|
+
- :pcode: MMR005D008
|
|
63
|
+
:name: Hkamti
|
|
64
|
+
:state: MMR005
|
|
65
|
+
- :pcode: MMR005D009
|
|
66
|
+
:name: Yinmabin
|
|
67
|
+
:state: MMR005
|
|
68
|
+
- :pcode: MMR006D001
|
|
69
|
+
:name: Dawei
|
|
70
|
+
:state: MMR006
|
|
71
|
+
- :pcode: MMR006D002
|
|
72
|
+
:name: Myeik
|
|
73
|
+
:state: MMR006
|
|
74
|
+
- :pcode: MMR006D003
|
|
75
|
+
:name: Kawthoung
|
|
76
|
+
:state: MMR006
|
|
77
|
+
- :pcode: MMR007D001
|
|
78
|
+
:name: Bago
|
|
79
|
+
:state: MMR111
|
|
80
|
+
- :pcode: MMR007D002
|
|
81
|
+
:name: Taungoo
|
|
82
|
+
:state: MMR111
|
|
83
|
+
- :pcode: MMR008D001
|
|
84
|
+
:name: Pyay
|
|
85
|
+
:state: MMR111
|
|
86
|
+
- :pcode: MMR008D002
|
|
87
|
+
:name: Thayarwady
|
|
88
|
+
:state: MMR111
|
|
89
|
+
- :pcode: MMR009D001
|
|
90
|
+
:name: Magway
|
|
91
|
+
:state: MMR009
|
|
92
|
+
- :pcode: MMR009D002
|
|
93
|
+
:name: Minbu
|
|
94
|
+
:state: MMR009
|
|
95
|
+
- :pcode: MMR009D003
|
|
96
|
+
:name: Thayet
|
|
97
|
+
:state: MMR009
|
|
98
|
+
- :pcode: MMR009D004
|
|
99
|
+
:name: Pakokku
|
|
100
|
+
:state: MMR009
|
|
101
|
+
- :pcode: MMR009D005
|
|
102
|
+
:name: Gangaw
|
|
103
|
+
:state: MMR009
|
|
104
|
+
- :pcode: MMR010D001
|
|
105
|
+
:name: Mandalay
|
|
106
|
+
:state: MMR010
|
|
107
|
+
- :pcode: MMR010D002
|
|
108
|
+
:name: Pyinoolwin
|
|
109
|
+
:state: MMR010
|
|
110
|
+
- :pcode: MMR010D003
|
|
111
|
+
:name: Kyaukse
|
|
112
|
+
:state: MMR010
|
|
113
|
+
- :pcode: MMR010D004
|
|
114
|
+
:name: Myingyan
|
|
115
|
+
:state: MMR010
|
|
116
|
+
- :pcode: MMR010D005
|
|
117
|
+
:name: Nyaung-U
|
|
118
|
+
:state: MMR010
|
|
119
|
+
- :pcode: MMR010D006
|
|
120
|
+
:name: Yamethin
|
|
121
|
+
:state: MMR010
|
|
122
|
+
- :pcode: MMR010D007
|
|
123
|
+
:name: Meiktila
|
|
124
|
+
:state: MMR010
|
|
125
|
+
- :pcode: MMR011D001
|
|
126
|
+
:name: Mawlamyine
|
|
127
|
+
:state: MMR011
|
|
128
|
+
- :pcode: MMR011D002
|
|
129
|
+
:name: Thaton
|
|
130
|
+
:state: MMR011
|
|
131
|
+
- :pcode: MMR012D001
|
|
132
|
+
:name: Sittwe
|
|
133
|
+
:state: MMR012
|
|
134
|
+
- :pcode: MMR012D005
|
|
135
|
+
:name: Mrauk-U
|
|
136
|
+
:state: MMR012
|
|
137
|
+
- :pcode: MMR012D002
|
|
138
|
+
:name: Maungdaw
|
|
139
|
+
:state: MMR012
|
|
140
|
+
- :pcode: MMR012D003
|
|
141
|
+
:name: Kyaukpyu
|
|
142
|
+
:state: MMR012
|
|
143
|
+
- :pcode: MMR012D004
|
|
144
|
+
:name: Thandwe
|
|
145
|
+
:state: MMR012
|
|
146
|
+
- :pcode: MMR013D001
|
|
147
|
+
:name: Yangon (North)
|
|
148
|
+
:state: MMR013
|
|
149
|
+
- :pcode: MMR013D002
|
|
150
|
+
:name: Yangon (East)
|
|
151
|
+
:state: MMR013
|
|
152
|
+
- :pcode: MMR013D003
|
|
153
|
+
:name: Yangon (South)
|
|
154
|
+
:state: MMR013
|
|
155
|
+
- :pcode: MMR013D004
|
|
156
|
+
:name: Yangon (West)
|
|
157
|
+
:state: MMR013
|
|
158
|
+
- :pcode: MMR014D001
|
|
159
|
+
:name: Taunggyi
|
|
160
|
+
:state: MMR222
|
|
161
|
+
- :pcode: MMR014D002
|
|
162
|
+
:name: Loilen
|
|
163
|
+
:state: MMR222
|
|
164
|
+
- :pcode: MMR014D003
|
|
165
|
+
:name: Langkho
|
|
166
|
+
:state: MMR222
|
|
167
|
+
- :pcode: MMR015D001
|
|
168
|
+
:name: Lashio
|
|
169
|
+
:state: MMR222
|
|
170
|
+
- :pcode: MMR015D002
|
|
171
|
+
:name: Muse
|
|
172
|
+
:state: MMR222
|
|
173
|
+
- :pcode: MMR015D003
|
|
174
|
+
:name: Kyaukme
|
|
175
|
+
:state: MMR222
|
|
176
|
+
- :pcode: MMR015D004
|
|
177
|
+
:name: Kunlong
|
|
178
|
+
:state: MMR222
|
|
179
|
+
- :pcode: MMR015D005
|
|
180
|
+
:name: Laukkaing
|
|
181
|
+
:state: MMR222
|
|
182
|
+
- :pcode: MMR015D006
|
|
183
|
+
:name: Hopang
|
|
184
|
+
:state: MMR222
|
|
185
|
+
- :pcode: MMR015D007
|
|
186
|
+
:name: Matman
|
|
187
|
+
:state: MMR222
|
|
188
|
+
- :pcode: MMR016D001
|
|
189
|
+
:name: Kengtung
|
|
190
|
+
:state: MMR222
|
|
191
|
+
- :pcode: MMR016D002
|
|
192
|
+
:name: Monghsat
|
|
193
|
+
:state: MMR222
|
|
194
|
+
- :pcode: MMR016D003
|
|
195
|
+
:name: Tachileik
|
|
196
|
+
:state: MMR222
|
|
197
|
+
- :pcode: MMR016D004
|
|
198
|
+
:name: Monghpyak
|
|
199
|
+
:state: MMR222
|
|
200
|
+
- :pcode: MMR017D001
|
|
201
|
+
:name: Pathein
|
|
202
|
+
:state: MMR017
|
|
203
|
+
- :pcode: MMR017D006
|
|
204
|
+
:name: Pyapon
|
|
205
|
+
:state: MMR017
|
|
206
|
+
- :pcode: MMR017D005
|
|
207
|
+
:name: Maubin
|
|
208
|
+
:state: MMR017
|
|
209
|
+
- :pcode: MMR017D003
|
|
210
|
+
:name: Myaungmya
|
|
211
|
+
:state: MMR017
|
|
212
|
+
- :pcode: MMR017D004
|
|
213
|
+
:name: Labutta
|
|
214
|
+
:state: MMR017
|
|
215
|
+
- :pcode: MMR017D002
|
|
216
|
+
:name: Hinthada
|
|
217
|
+
:state: MMR017
|
|
218
|
+
- :pcode: MMR018D001
|
|
219
|
+
:name: Naypyitaw (North)
|
|
220
|
+
:state: MMR018
|
|
221
|
+
- :pcode: MMR018D002
|
|
222
|
+
:name: Naypyitaw (South)
|
|
223
|
+
:state: MMR018
|