nayyar 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 080fe4ea4cca3830776db05bc161573574ce2040
4
- data.tar.gz: fefda208dc6000e1e6fb556e1b419410ca4180cc
2
+ SHA256:
3
+ metadata.gz: b2214fdcbce8558b80e51d36d46ae9782ad6e2b1069b039b40cb77a26cbbc261
4
+ data.tar.gz: bb7a84322f286cd4b0df42f524dd9f0b1c38a5c0351b9b290d6eb9d9b27f023f
5
5
  SHA512:
6
- metadata.gz: 19c22e4015599bdae5058bdb8a55e7de45d859c9aa5825779b6172b7f7b132a9278fd69a8e7a582af93d01f2c85664b472e955f7f879acaa4438921ed89e89de
7
- data.tar.gz: 3812e732b7f5aaf96c19b0651010ce9a6d5a94e0d9000bc345007803fa9155e8c2aeb5c79e35e6887d6fcb74c27064ccadcf9c65b46a0df621eb2adf0e42c4e2
6
+ metadata.gz: 58fde7fc55bfafa3bec000b93a27d3ec4a604052df3595c5ab4792265f69e4a3e378a6ee9738cd6206b00b9f35244d884ea451c3ae1dfe7ccffda0ab41b76e00
7
+ data.tar.gz: 53d14ecff7dcc82f15f0ec86dfac166b31e0d0f2bbac43c773ced6c304ed57ac07fc89517f365336b051d8eddf06ca33aea689b4d59bb89b9076200039bd537a
@@ -0,0 +1,38 @@
1
+ # Use the latest 2.1 version of CircleCI pipeline process engine.
2
+ # See: https://circleci.com/docs/2.0/configuration-reference
3
+ version: 2.1
4
+
5
+ # Orbs are reusable packages of CircleCI configuration that you may share across projects, enabling you to create encapsulated, parameterized commands, jobs, and executors that can be used across multiple projects.
6
+ # See: https://circleci.com/docs/2.0/orb-intro/
7
+ orbs:
8
+ ruby: circleci/ruby@1.8.0
9
+
10
+ # Define a job to be invoked later in a workflow.
11
+ # See: https://circleci.com/docs/2.0/configuration-reference/#jobs
12
+ jobs:
13
+ rspec:
14
+ docker:
15
+ - image: cimg/ruby:3.1.2
16
+ executor: ruby/default
17
+ steps:
18
+ - checkout
19
+ - run:
20
+ name: Which bundler?
21
+ command: bundle -v
22
+ - run:
23
+ name: bundle install
24
+ command: bundle _2.3.11_ install
25
+ - run:
26
+ name: rubocop
27
+ command: rubocop
28
+ - run:
29
+ name: rspec
30
+ command: rspec
31
+
32
+ # Invoke jobs via workflows
33
+ # See: https://circleci.com/docs/2.0/configuration-reference/#workflows
34
+ workflows:
35
+ rspec: # This is the name of the workflow, feel free to change it to better match your workflow.
36
+ # Inside the workflow, you define the jobs you want to run.
37
+ jobs:
38
+ - rspec
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ TargetRubyVersion: 2.7.0
4
+
5
+ Style/ClassAndModuleChildren:
6
+ EnforcedStyle: compact
7
+
8
+ Metrics/BlockLength:
9
+ Exclude:
10
+ - 'nayyar.gemspec'
11
+ - 'spec/*.rb'
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in nayyar.gemspec
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Nayyar / နေရာ
2
- [![Build Status](https://travis-ci.org/mmhan/nayyar.png)](https://travis-ci.org/mmhan/nayyar.png)
2
+ [![CircleCI](https://circleci.com/gh/mmhan/nayyar/tree/master.svg?style=svg)](https://circleci.com/gh/mmhan/nayyar/tree/master)
3
3
 
4
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
5
 
6
6
  15 States are indexed by MIMU's pcode, ISO3166-2:MM and alpha3 codes used in plate numbers by transportation authority.
7
7
  74 Districts and 413 Townships are indexed by MIMU's pcode.
8
8
 
9
- The current version is `0.1.0` and it uses [Semantic Versioning](http://semver.org/)
9
+ The current version is [![Gem Version](https://badge.fury.io/rb/nayyar.svg)](http://badge.fury.io/rb/nayyar) and it uses [Semantic Versioning](http://semver.org/)
10
10
 
11
11
  ## Installation
12
12
 
@@ -67,11 +67,13 @@ Use any of the `find_by` or `find_by_**index_name**` with a bang `!` to trigger
67
67
  ### Districts
68
68
 
69
69
  Find all districts using
70
+
70
71
  ```ruby
71
72
  Nayyar::District.all
72
73
  ```
73
74
 
74
75
  Find districts under a certain state using
76
+
75
77
  ```ruby
76
78
  shan_state = Nayyar::State.find_by_alpha3("SHN")
77
79
  # get an array of all districts under Shan state using
@@ -81,6 +83,7 @@ Nayyar::District.of_state(shan_state)
81
83
  ```
82
84
 
83
85
  Find a district using pcode
86
+
84
87
  ```ruby
85
88
  Nayyar::District.find_by_pcode("MMR001D001")
86
89
  # or
@@ -90,6 +93,7 @@ Nayyar::District.find_by(pcode:"MMR001D001")
90
93
  ```
91
94
 
92
95
  Find the state that a district belongs to using
96
+
93
97
  ```ruby
94
98
  Nayyar::District.find_by(pcode:"MMR001D001").state
95
99
 
@@ -101,11 +105,13 @@ Use any of the `find_by` or `find_by_**index_name**` with a bang `!` to trigger
101
105
  ### Townships
102
106
 
103
107
  Find all townships using
108
+
104
109
  ```ruby
105
110
  Nayyar::Townships.all
106
111
  ```
107
112
 
108
113
  Find townships under a certain state using
114
+
109
115
  ```ruby
110
116
  ygn_east = Nayyar::District.find_by_pcode "MMR013D002"
111
117
  # get an array of all districts under Shan state using
@@ -115,6 +121,7 @@ Nayyar::Township.of_district(ygn_east)
115
121
  ```
116
122
 
117
123
  Find a township using pcode
124
+
118
125
  ```ruby
119
126
  Nayyar::Township.find_by_pcode("MMR013017")
120
127
  # or
@@ -124,30 +131,25 @@ Nayyar::Township.find_by(pcode:"MMR013017")
124
131
  ```
125
132
 
126
133
  Find the district that a township belongs to using
134
+
127
135
  ```ruby
128
- Nayyar::Township.find_by(pcode:"MMR013017").township
136
+ Nayyar::Township.find_by(pcode:"MMR013017").district
129
137
 
130
138
  # => <Nayyar::District:0x007fb8a5ad14d8 @data={:pcode=>"MMR013D002", :name=>"Yangon (East)", :state=>"MMR013"}>
131
139
  ```
132
140
 
133
141
  Use any of the `find_by` or `find_by_**index_name**` with a bang `!` to trigger `Nayyar::TownshipNotFound` error.
134
- <!--
142
+
135
143
  ## Development
136
144
 
137
145
  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.
146
+
147
+ All data-related files are in the lib/data directory. `locations.csv` file is the source of truth, which includes States, Districts, and Townships data. YAML files are generated
148
+ by extracting the data from the `locations.csv` file. Do not update directly to YAML files. Any updates must be made in the `locations.csv` file and extracted to YAML files by running `bin/seed`.
138
149
 
139
150
  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
151
 
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.
152
+ If you feel that I have missed out your use-case or find an issue with this gem [please submit an issue](https://github.com/mmhan/nayyar/issues/new).
151
153
 
152
154
  ## Contributing
153
155
 
@@ -155,4 +157,100 @@ If you feel that I have missed out your use-case or if you wanna add other goals
155
157
  2. Create your feature branch (`git checkout -b feature/my-new-feature`)
156
158
  3. Commit your changes (`git commit -am 'Add some feature'`)
157
159
  4. Push to the branch (`git push origin feature/my-new-feature`)
158
- 5. Create a new Pull Request
160
+ 5. Create a new Pull Request
161
+
162
+
163
+ ## Documentation
164
+
165
+ Since, this is a pretty small library, a documentation hasn't been created yet. Nonetheless, here's the rspec output with documentation format.
166
+
167
+ ```
168
+ Nayyar
169
+ has a version number
170
+
171
+ Nayyar::State
172
+ class methods
173
+ .all
174
+ should be a kind of Array
175
+ contains hashes of state data
176
+ .find_by
177
+ returns state when it finds it
178
+ will return nil if state is not found
179
+ will raise ArgumentError if no argument is provided
180
+ will raise ArgumentError if wrong argument is provided
181
+ .find_by!
182
+ should be a kind of Nayyar::State
183
+ will raise error if the state isn't found
184
+ .find_by_**indices**
185
+ returns state when it finds it
186
+ returns nil when it can't be found
187
+ .find_by_**indices**!
188
+ returns state when it finds it
189
+ raise error when it can't be found
190
+ #initialize
191
+ allows to create a state by providing hash data
192
+ attributes
193
+ allows its attributes to be accessed by methods
194
+ allows its attributes to be accessed as keys
195
+ #districts
196
+ return a list of districts under given state
197
+
198
+ Nayyar::District
199
+ class methods
200
+ .all
201
+ should return all districts
202
+ .of_state
203
+ return a list of districts under given state
204
+ .find_by
205
+ should be a kind of Nayyar::District
206
+ returns nil if it's not found
207
+ .find_by!
208
+ should be a kind of Nayyar::District
209
+ raise error if it's not found
210
+ .find_by_**indices**
211
+ returns state when it finds it
212
+ returns nil when it can't be found
213
+ .find_by_**indices**!
214
+ returns state when it finds it
215
+ raise error when it can't be found
216
+ #initialize
217
+ allows to create a district by providing hash data
218
+ attributes
219
+ allows its attributes to be accessed by methods
220
+ allows its attributes to be accessed as keys
221
+ #state
222
+ should be a kind of Nayyar::State
223
+ expect it to be a correct state
224
+ .townships
225
+ return a list of districts under given district
226
+
227
+ Nayyar::Township
228
+ class methods
229
+ .all
230
+ should return all township
231
+ .of_district
232
+ return a list of districts under given district
233
+ .find_by
234
+ should be a kind of Nayyar::Township
235
+ returns nil if it's not found
236
+ .find_by!
237
+ should be a kind of Nayyar::Township
238
+ raise error if it's not found
239
+ .find_by_**indices**
240
+ returns state when it finds it
241
+ returns nil when it can't be found
242
+ .find_by_**indices**!
243
+ returns state when it finds it
244
+ raise error when it can't be found
245
+ #initialize
246
+ allows to create a township by providing hash data
247
+ attributes
248
+ allows its attributes to be accessed by methods
249
+ allows its attributes to be accessed as keys
250
+ #district
251
+ should be a kind of Nayyar::District
252
+ expect it to be a correct state
253
+
254
+ Finished in 0.1254 seconds (files took 0.1826 seconds to load)
255
+ 48 examples, 0 failures
256
+ ```
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "nayyar"
4
+ require 'bundler/setup'
5
+ require 'nayyar'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "nayyar"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start
data/bin/seed ADDED
@@ -0,0 +1,11 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ # Parentheses are used to run the command in a subshell. Ruuning a command
6
+ # in sub-shell allows you to stay on the current directory after running
7
+ # the command.
8
+
9
+ (cd lib/data && bundle exec ruby extract.rb)
10
+
11
+ echo "Seeding done"
data/lib/.DS_Store ADDED
Binary file
@@ -1,223 +1,297 @@
1
1
  ---
2
2
  - :pcode: MMR001D001
3
3
  :name: Myitkyina
4
+ :my_name: မြစ်ကြီးနား
4
5
  :state: MMR001
5
6
  - :pcode: MMR001D002
6
7
  :name: Mohnyin
8
+ :my_name: မိုးညှင်
7
9
  :state: MMR001
8
10
  - :pcode: MMR001D003
9
11
  :name: Bhamo
12
+ :my_name: ဗန်းမော်
10
13
  :state: MMR001
11
14
  - :pcode: MMR001D004
12
15
  :name: Puta-O
16
+ :my_name: ပူတာအို
13
17
  :state: MMR001
14
18
  - :pcode: MMR002D001
15
19
  :name: Loikaw
20
+ :my_name: လွိုင်ကော်
16
21
  :state: MMR002
17
22
  - :pcode: MMR002D002
18
23
  :name: Bawlake
24
+ :my_name: ဘော်လခဲ
19
25
  :state: MMR002
20
26
  - :pcode: MMR003D001
21
27
  :name: Hpa-An
28
+ :my_name: ဘားအံ
22
29
  :state: MMR003
23
30
  - :pcode: MMR003D004
24
31
  :name: Hpapun
32
+ :my_name: ဖာပွန်
25
33
  :state: MMR003
26
34
  - :pcode: MMR003D002
27
35
  :name: Myawaddy
36
+ :my_name: မြဝတီ
28
37
  :state: MMR003
29
38
  - :pcode: MMR003D003
30
39
  :name: Kawkareik
40
+ :my_name: ကော့ကရိတ်
31
41
  :state: MMR003
32
42
  - :pcode: MMR004D003
33
43
  :name: Hakha
44
+ :my_name: ဟားခါး
34
45
  :state: MMR004
35
46
  - :pcode: MMR004D001
36
47
  :name: Falam
48
+ :my_name: ဖလမ်း
37
49
  :state: MMR004
38
50
  - :pcode: MMR004D002
39
51
  :name: Mindat
52
+ :my_name: မင်းတပ်
40
53
  :state: MMR004
41
54
  - :pcode: MMR005D001
42
55
  :name: Sagaing
56
+ :my_name: စစ်ကိုင်း
43
57
  :state: MMR005
44
58
  - :pcode: MMR005D002
45
59
  :name: Shwebo
60
+ :my_name: ရွှေဘို
46
61
  :state: MMR005
47
62
  - :pcode: MMR005D003
48
63
  :name: Monywa
64
+ :my_name: မုံရွာ
49
65
  :state: MMR005
50
66
  - :pcode: MMR005D004
51
67
  :name: Katha
68
+ :my_name: ကသာ
52
69
  :state: MMR005
53
70
  - :pcode: MMR005D005
54
71
  :name: Kale
72
+ :my_name: ကလေး
55
73
  :state: MMR005
56
74
  - :pcode: MMR005D006
57
75
  :name: Tamu
76
+ :my_name: တမူး
58
77
  :state: MMR005
59
78
  - :pcode: MMR005D007
60
79
  :name: Mawlaik
80
+ :my_name: မော်လိုက်
61
81
  :state: MMR005
62
82
  - :pcode: MMR005D008
63
83
  :name: Hkamti
84
+ :my_name: ခန္တီး
64
85
  :state: MMR005
65
86
  - :pcode: MMR005D009
66
87
  :name: Yinmabin
88
+ :my_name: ယင်းမာပင်
67
89
  :state: MMR005
68
90
  - :pcode: MMR006D001
69
91
  :name: Dawei
92
+ :my_name: ထားဝယ်
70
93
  :state: MMR006
71
94
  - :pcode: MMR006D002
72
95
  :name: Myeik
96
+ :my_name: မြိတ်
73
97
  :state: MMR006
74
98
  - :pcode: MMR006D003
75
99
  :name: Kawthoung
100
+ :my_name: ကော့သောင်း
76
101
  :state: MMR006
77
102
  - :pcode: MMR007D001
78
103
  :name: Bago
104
+ :my_name: ပဲခူး
79
105
  :state: MMR111
80
106
  - :pcode: MMR007D002
81
107
  :name: Taungoo
108
+ :my_name: တောင်ငူ
82
109
  :state: MMR111
83
110
  - :pcode: MMR008D001
84
111
  :name: Pyay
112
+ :my_name: ပြည်
85
113
  :state: MMR111
86
114
  - :pcode: MMR008D002
87
115
  :name: Thayarwady
116
+ :my_name: သာယာဝတီ
88
117
  :state: MMR111
89
118
  - :pcode: MMR009D001
90
119
  :name: Magway
120
+ :my_name: မကွေး
91
121
  :state: MMR009
92
122
  - :pcode: MMR009D002
93
123
  :name: Minbu
124
+ :my_name: မင်းဘူး
94
125
  :state: MMR009
95
126
  - :pcode: MMR009D003
96
127
  :name: Thayet
128
+ :my_name: သရက်
97
129
  :state: MMR009
98
130
  - :pcode: MMR009D004
99
131
  :name: Pakokku
132
+ :my_name: ပခုက္ကူ
100
133
  :state: MMR009
101
134
  - :pcode: MMR009D005
102
135
  :name: Gangaw
136
+ :my_name: ဂန့်ဂေါ
103
137
  :state: MMR009
104
138
  - :pcode: MMR010D001
105
139
  :name: Mandalay
140
+ :my_name: မန္တလေး
106
141
  :state: MMR010
107
142
  - :pcode: MMR010D002
108
143
  :name: Pyinoolwin
144
+ :my_name: ပြင်ဦးလွင်
109
145
  :state: MMR010
110
146
  - :pcode: MMR010D003
111
147
  :name: Kyaukse
148
+ :my_name: ကျောက်ဆည်
112
149
  :state: MMR010
113
150
  - :pcode: MMR010D004
114
151
  :name: Myingyan
152
+ :my_name: မြင်းခြံ
115
153
  :state: MMR010
116
154
  - :pcode: MMR010D005
117
155
  :name: Nyaung-U
156
+ :my_name: ညောင်ဦး
118
157
  :state: MMR010
119
158
  - :pcode: MMR010D006
120
159
  :name: Yamethin
160
+ :my_name: ရမည်းသင်း
121
161
  :state: MMR010
122
162
  - :pcode: MMR010D007
123
163
  :name: Meiktila
164
+ :my_name: မိတ္ထီလာ
124
165
  :state: MMR010
125
166
  - :pcode: MMR011D001
126
167
  :name: Mawlamyine
168
+ :my_name: မော်လမြိုင်
127
169
  :state: MMR011
128
170
  - :pcode: MMR011D002
129
171
  :name: Thaton
172
+ :my_name: သထုံ
130
173
  :state: MMR011
131
174
  - :pcode: MMR012D001
132
175
  :name: Sittwe
176
+ :my_name: စစ်တွေ
133
177
  :state: MMR012
134
178
  - :pcode: MMR012D005
135
179
  :name: Mrauk-U
180
+ :my_name: မြောက်ဦး
136
181
  :state: MMR012
137
182
  - :pcode: MMR012D002
138
183
  :name: Maungdaw
184
+ :my_name: မောင်တော
139
185
  :state: MMR012
140
186
  - :pcode: MMR012D003
141
187
  :name: Kyaukpyu
188
+ :my_name: ကျောက်ဖြူ
142
189
  :state: MMR012
143
190
  - :pcode: MMR012D004
144
191
  :name: Thandwe
192
+ :my_name: သံတွဲ
145
193
  :state: MMR012
146
194
  - :pcode: MMR013D001
147
195
  :name: Yangon (North)
196
+ :my_name: ရန်ကုန်(မြောက်ပိုင်း)
148
197
  :state: MMR013
149
198
  - :pcode: MMR013D002
150
199
  :name: Yangon (East)
200
+ :my_name: ရန်ကုန်(အရှေ့ပိုင်း)
151
201
  :state: MMR013
152
202
  - :pcode: MMR013D003
153
203
  :name: Yangon (South)
204
+ :my_name: ရန်ကုန်(တောင်ပိုင်း)
154
205
  :state: MMR013
155
206
  - :pcode: MMR013D004
156
207
  :name: Yangon (West)
208
+ :my_name: ရန်ကုန်(အနောက်ပိုင်း)
157
209
  :state: MMR013
158
210
  - :pcode: MMR014D001
159
211
  :name: Taunggyi
212
+ :my_name: တောင်ကြီး
160
213
  :state: MMR222
161
214
  - :pcode: MMR014D002
162
215
  :name: Loilen
216
+ :my_name: လွိုင်လင်
163
217
  :state: MMR222
164
218
  - :pcode: MMR014D003
165
219
  :name: Langkho
220
+ :my_name: လင်းခေး
166
221
  :state: MMR222
167
222
  - :pcode: MMR015D001
168
223
  :name: Lashio
224
+ :my_name: လားရှိုး
169
225
  :state: MMR222
170
226
  - :pcode: MMR015D002
171
227
  :name: Muse
228
+ :my_name: မူစယ်
172
229
  :state: MMR222
173
230
  - :pcode: MMR015D003
174
231
  :name: Kyaukme
232
+ :my_name: ကျောက်မဲ
175
233
  :state: MMR222
176
234
  - :pcode: MMR015D004
177
235
  :name: Kunlong
236
+ :my_name: ကွမ်းလုံ
178
237
  :state: MMR222
179
238
  - :pcode: MMR015D005
180
239
  :name: Laukkaing
240
+ :my_name: လောက်ကိုင်
181
241
  :state: MMR222
182
242
  - :pcode: MMR015D006
183
243
  :name: Hopang
244
+ :my_name: ဟိုပန်
184
245
  :state: MMR222
185
246
  - :pcode: MMR015D007
186
247
  :name: Matman
248
+ :my_name: မက်မန်း
187
249
  :state: MMR222
188
250
  - :pcode: MMR016D001
189
251
  :name: Kengtung
252
+ :my_name: ကျိုင်းတုံ
190
253
  :state: MMR222
191
254
  - :pcode: MMR016D002
192
255
  :name: Monghsat
256
+ :my_name: မိုင်းဆတ်
193
257
  :state: MMR222
194
258
  - :pcode: MMR016D003
195
259
  :name: Tachileik
260
+ :my_name: တာချီလိတ်
196
261
  :state: MMR222
197
262
  - :pcode: MMR016D004
198
263
  :name: Monghpyak
264
+ :my_name: မိုင်းဖြတ်
199
265
  :state: MMR222
200
266
  - :pcode: MMR017D001
201
267
  :name: Pathein
268
+ :my_name: ပုသိမ်
202
269
  :state: MMR017
203
270
  - :pcode: MMR017D006
204
271
  :name: Pyapon
272
+ :my_name: ဖျာပုံ
205
273
  :state: MMR017
206
274
  - :pcode: MMR017D005
207
275
  :name: Maubin
276
+ :my_name: မအူပင်
208
277
  :state: MMR017
209
278
  - :pcode: MMR017D003
210
279
  :name: Myaungmya
280
+ :my_name: မြောင်းမြ
211
281
  :state: MMR017
212
282
  - :pcode: MMR017D004
213
283
  :name: Labutta
284
+ :my_name: လပွတ္တာ
214
285
  :state: MMR017
215
286
  - :pcode: MMR017D002
216
287
  :name: Hinthada
288
+ :my_name: ဟင်္သာတ
217
289
  :state: MMR017
218
290
  - :pcode: MMR018D001
219
291
  :name: Naypyitaw (North)
292
+ :my_name: နေပြည်တော်(မြောက်ပိုင်း)
220
293
  :state: MMR018
221
294
  - :pcode: MMR018D002
222
295
  :name: Naypyitaw (South)
296
+ :my_name: နေပြည်တော်(တောင်ပိုင်း)
223
297
  :state: MMR018
data/lib/data/extract.rb CHANGED
@@ -1,3 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Extract data from locations.csv which will be the source of data for the gem
4
+ # and create states.yml, districts.yml and townships.yml which will be read at runtime
5
+
1
6
  require 'csv'
2
7
  require 'pry'
3
8
  require 'psych'
@@ -6,14 +11,40 @@ states = []
6
11
  districts = []
7
12
  townships = []
8
13
 
9
- CSV.foreach("locations.csv") do |iso, s_pcode, alpha3, state, d_pcode, district, t_pcode, township|
10
- states << {iso: iso, pcode: s_pcode, alpha3: alpha3, name: state}
11
- districts << {pcode: d_pcode, name: district, state: s_pcode} unless d_pcode.nil?
12
- townships << {pcode: t_pcode, name: township, district: d_pcode} unless t_pcode.nil?
14
+ def state(location)
15
+ { iso: location[:iso], pcode: location[:s_pcode], alpha3: location[:alpha3], name: location[:state],
16
+ my_name: location[:state_in_my] }
17
+ end
18
+
19
+ def district?(location)
20
+ !location[:d_pcode].nil?
21
+ end
22
+
23
+ def district(location)
24
+ { pcode: location[:d_pcode], name: location[:district], my_name: location[:district_in_my],
25
+ state: location[:s_pcode] }
26
+ end
27
+
28
+ def township?(location)
29
+ !location[:t_pcode].nil?
30
+ end
31
+
32
+ def township(location)
33
+ { pcode: location[:t_pcode], name: location[:township], my_name: location[:township_in_my],
34
+ district: location[:d_pcode] }
35
+ end
36
+
37
+ CSV.foreach('locations.csv') do |location_csv_data|
38
+ keys = %i[iso s_pcode alpha3 state state_in_my d_pcode district district_in_my t_pcode township
39
+ township_in_my]
40
+ location = keys.zip(*location_csv_data).to_h
41
+ states << state(location)
42
+ districts << district(location) if district?(location)
43
+ townships << township(location) if township?(location)
13
44
  end
14
45
  states.uniq! { |state| state[:pcode] }
15
- districts.uniq! { |districts| districts[:pcode] }
46
+ districts.uniq! { |district| district[:pcode] }
16
47
 
17
- File.open("states.yml", "w") { |f| f.write states.to_yaml }
18
- File.open("districts.yml", "w") { |f| f.write districts.to_yaml }
19
- File.open("townships.yml", "w") { |f| f.write townships.to_yaml }
48
+ File.write('states.yml', states.to_yaml)
49
+ File.write('districts.yml', districts.to_yaml)
50
+ File.write('townships.yml', townships.to_yaml)