pumi 0.12.2 → 0.13.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: c338fd7c9989d517c568b220fad0700b141044673b46ecf908fe40692890c96f
4
- data.tar.gz: 57c0a0a287d5fd3fe892697eef9c5c480fdba8efa6fdf3106fda5af420d0d999
3
+ metadata.gz: c7df0e8620fb33e07db08efc84310967c1ce09c545de619b98c7b8294baab835
4
+ data.tar.gz: d752627f28b601a273508e7868de577dc2498b61278955152a88a7890552c992
5
5
  SHA512:
6
- metadata.gz: 81a711486ae8400838a02c1253b406ef779a025426cddd9b545220b1508936635888a51132474f80733002fa8a4d8890c2cf83cf7001602a4fa5cdc6bcf961d9
7
- data.tar.gz: 89038beb7b19c9e5f17693fcffac6f5cfba9451171d64d31377b06b1cb578ef5fe6e3a5f32dc7c66103623f8273c25bcf0021eb89d391fb3cbb73da5ca2c0d1e
6
+ metadata.gz: abebda567ad01aceb9ab68279f37456870dedb498c89e2b8465b215fb453da437a1963924fd1342a5f55a904a4ae76943ad76fd523f6af1f29d2f722509a3d20
7
+ data.tar.gz: 420fd418789d76c2eef6ce332c75d92c08fead8d99b902b8ccf43816e26f1bfa9ebc4d75cf3d58579906e0a1ca6202d85a5d6d4869bf9c0bf194a3a1a134c4e8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.13.1](https://github.com/dwilkie/pumi/compare/v0.13.0...v0.13.1) (2023-03-02)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * Improve data parser ([#35](https://github.com/dwilkie/pumi/issues/35)) ([f17ebf5](https://github.com/dwilkie/pumi/commit/f17ebf5eba26d88f4fff4fb5bb2461d1817a0829))
9
+
10
+ ## [0.13.0](https://github.com/dwilkie/pumi/compare/v0.12.2...v0.13.0) (2023-02-06)
11
+
12
+
13
+ ### Features
14
+
15
+ * Update data ([#33](https://github.com/dwilkie/pumi/issues/33)) ([ab06018](https://github.com/dwilkie/pumi/commit/ab06018c19f1546c8d1c2c53b154623037301563))
16
+
3
17
  ## [0.12.2](https://github.com/dwilkie/pumi/compare/v0.12.1...v0.12.2) (2023-02-01)
4
18
 
5
19
 
data/README.md CHANGED
@@ -8,13 +8,13 @@ Pumi (ភូមិ pronounced Poom, which means Village in Khmer) is an Open Sou
8
8
 
9
9
  ## Demo and API
10
10
 
11
- A [JSON API](https://pumiapp.herokuapp.com) is available to if you're not using Ruby or if you just don't want to install a local copy of the data. The [API Start Page](https://pumiapp.herokuapp.com) also shows a Demo of a UI for for entering any location in Cambodia.
11
+ A [JSON API](https://pumi.onrender.com/) is available to if you're not using Ruby or if you just don't want to install a local copy of the data. The [API Start Page](https://pumi.onrender.com/) also shows a Demo of a UI for for entering any location in Cambodia.
12
12
 
13
13
  ## Usage
14
14
 
15
15
  ### Rails
16
16
 
17
- Using Pumi with Rails gives you some javascript helpers as well as an API to filter and select Provinces (ខេត្ត), Districts (ស្រុក / ខណ្ឌ), Communes (ឃុំ / សង្កាត់) and Villages (ភូមិ) in both latin and Khmer as seen below and in the [Pumi API Start Page](https://pumiapp.herokuapp.com)
17
+ Using Pumi with Rails gives you some javascript helpers as well as an API to filter and select Provinces (ខេត្ត), Districts (ស្រុក / ខណ្ឌ), Communes (ឃុំ / សង្កាត់) and Villages (ភូមិ) in both latin and Khmer as seen below and in the [Pumi API Start Page](https://pumi.onrender.com/)
18
18
 
19
19
  ![Pumi UI Latin](https://raw.githubusercontent.com/dwilkie/pumi/master/pumi_ui_en.png)
20
20
  ![Pumi UI Khmer](https://raw.githubusercontent.com/dwilkie/pumi/master/pumi_ui_km.png)
data/bin/parse_data CHANGED
@@ -4,63 +4,9 @@
4
4
 
5
5
  # $ parse_data
6
6
 
7
- require "pathname"
8
- require "csv"
9
- require "yaml"
7
+ require "bundler/setup"
8
+ require "pumi"
10
9
 
11
- DEFAULT_DATA_LOCATION = "tmp/*.csv".freeze
12
- HEADERS = %w[type code name_km name_latin reference note1 note2].freeze
13
- CODE_LENGTHS = {
14
- 4 => "districts",
15
- 6 => "communes",
16
- 8 => "villages"
17
- }.freeze
18
-
19
- # https://en.wikipedia.org/wiki/Administrative_divisions_of_Cambodia
20
- # https://en.wikipedia.org/wiki/Romanization_of_Khmer
21
- # https://en.wikipedia.org/wiki/United_Nations_Group_of_Experts_on_Geographical_Names
22
-
23
- AdministrativeUnit = Struct.new(:en, :km, :latin, keyword_init: true)
24
- ADMINISTRATIVE_UNITS = {
25
- "ស្រុក" => AdministrativeUnit.new(en: "District", km: "ស្រុក", latin: "Srok"),
26
- "ខណ្ឌ" => AdministrativeUnit.new(en: "Section", km: "ខណ្ឌ", latin: "Khan"),
27
- "ឃុំ" => AdministrativeUnit.new(en: "Commune", km: "ឃុំ", latin: "Khum"),
28
- "សង្កាត់" => AdministrativeUnit.new(en: "Quarter", km: "សង្កាត់", latin: "Sangkat"),
29
- "ភូមិ" => AdministrativeUnit.new(en: "Village", km: "ភូមិ", latin: "Phum"),
30
- "ក្រុង" => AdministrativeUnit.new(en: "Municipality", km: "ក្រុង", latin: "Krong")
31
- }.freeze
32
-
33
- data = {}
34
-
35
- Pathname.glob(DEFAULT_DATA_LOCATION).select(&:file?).each do |file|
36
- CSV.read(file, headers: HEADERS).each do |row|
37
- code = row.fetch("code")
38
- next if code.to_s.gsub(/\D/, "").empty?
39
-
40
- code = code.rjust(code.length + 1, "0") if code.length.odd?
41
- location_type = CODE_LENGTHS.fetch(code.length)
42
- administrative_unit = ADMINISTRATIVE_UNITS.fetch(row.fetch("type"))
43
-
44
- data[location_type] ||= {}
45
- data[location_type][code] = {
46
- "name" => {
47
- "km" => row.fetch("name_km"),
48
- "latin" => row.fetch("name_latin")
49
- },
50
- "administrative_unit" => {
51
- "km" => administrative_unit.km,
52
- "latin" => administrative_unit.latin,
53
- "en" => administrative_unit.en
54
- }
55
- }
56
- end
57
- end
58
-
59
- if data.any?
60
- CODE_LENGTHS.each do |_, type|
61
- File.write(
62
- "data/#{type}.yml",
63
- { type => data.fetch(type).sort.to_h }.to_yaml
64
- )
65
- end
66
- end
10
+ data_parser = Pumi::DataParser.new
11
+ data = data_parser.load_data!
12
+ data_parser.write_data!(data)