ko_region_code_mapper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a2d67cb60e0737d568fd0869f8492e8c4f7c01f3a1bc7824c142c1e64263f73d
4
+ data.tar.gz: 49ca6e4f5793c608353f44369bca218d66d216c0808cccb493debf6e97db4aec
5
+ SHA512:
6
+ metadata.gz: a7c03a7029203c96fa5862dcbcbc9aa77e93b093d870f1cddc26faf126c0fb7a7bef2dacf22398780dffc08f7adf7d8f24fecfb425b0febb12e568d06a8dd321
7
+ data.tar.gz: 60498bfb426c233864cabf7451730746b0deac8aafdc03c13470ad0b73001328e763b3b602387150fd4edade7c1db98662069f8c3bcb322a49dcda9a3b2fea9c
@@ -0,0 +1 @@
1
+ 시도,시군구,행정구역명,행정동(행정기관명),법정동,행정구역분류,행정기관코드,행정기관 생성일,법정동코드,행정동 영문명칭
@@ -0,0 +1,58 @@
1
+ ## encoding: utf-8
2
+ $:.unshift File.dirname(__FILE__)
3
+
4
+ require 'csv'
5
+
6
+ class KoRegionCodeMapper
7
+ FILE_NAME = 'data/ko_region_20181231.csv'
8
+ DATA_INDEX = {
9
+ :sido => 0,
10
+ :sigungu => 1,
11
+ :hname => 2,
12
+ :hdong => 3,
13
+ :bdong => 4,
14
+ :hcategory => 5,
15
+ :hcode => 6,
16
+ :hcreated_at => 7,
17
+ :bcode => 8,
18
+ :hname_en => 9
19
+ }
20
+
21
+ def initialize(opts = { filename: FILE_NAME, include_header: true, index_mapping: DATA_INDEX })
22
+ if opts != nil && (opts[:filename].empty? || opts[:include_header].nil? || opts[:index_mapping].empty?)
23
+ raise ArgumentError.new("[ERROR] Check opts parameter. It should include appropriate 'filename', 'include_header', 'index_mapping'.(given: #{opts})")
24
+ end
25
+
26
+ if opts[:index_mapping].class != Hash
27
+ raise ArgumentError.new("[ERROR] Check opts[:index_mapping]. It should be hash consist of (key, value) presenting (attribute_name, index of column in table)")
28
+ end
29
+
30
+ @index_map = opts[:index_mapping] || DATA_INDEX
31
+
32
+ file = CSV.read(File.expand_path(File.dirname(__FILE__) + "/#{opts[:filename] || FILE_NAME}"))
33
+ @headers = file.delete_at(0) if opts[:include_header] || true
34
+ @data = file
35
+ end
36
+
37
+ def find_sigungu_code_by_hcode(hcode)
38
+ row = find_by_hcode(hcode).first
39
+ row[@index_map[:hcategory]]&.slice(0..4)
40
+ end
41
+
42
+ def find_hcodes_by_sigungu_code(sigungu_code)
43
+ row = find_by_sigungu_code(sigungu_code)
44
+ row.map { |d| d[@index_map[:hcode]].to_s }
45
+ end
46
+
47
+ private
48
+
49
+ def find_by_hcode(hcode)
50
+ idx = @index_map[:hcode]
51
+ @data.select { |row| row[idx].to_s.eql? hcode.to_s }
52
+ end
53
+
54
+ def find_by_sigungu_code(sigungu_code)
55
+ idx = @index_map[:hcategory]
56
+ @data.select{ |row| row[idx].to_s.start_with? sigungu_code }
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ko_region_code_mapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aree Oh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: csv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Serve interfaces converting between multiple region codes
28
+ email: christina.ohari@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/data/ko_region_20181231.csv
34
+ - lib/ko_region_code_mapper.rb
35
+ homepage: https://github.com/aria-grande/KoRegionCodeMapper
36
+ licenses:
37
+ - MIT
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.7.6
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Korean region code Mapper
59
+ test_files: []