cn-gb2260 1.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: 9276a8f0617a83bb3e145ddd208a29c24205232e25ad0ed8de61cd5d07ed03be
4
+ data.tar.gz: aa1f68ed9bad4767ddbb12fc13a31212b5ddc1f5f5b8033a249acb8e6cd99f75
5
+ SHA512:
6
+ metadata.gz: 9c29bd89ca48de1b6b999cf03b2b900acc8303d44f75c2a842e9a9487edbb4c539a566b66d702f1350582d8763ef008397ba78813978f83b071db9ac76a0dd63
7
+ data.tar.gz: 7ef4f639923a46c2915023cb2186116ed54e3df67ba4c61ba4bdb096d6c2ad40630046e3089540dc3a68bec38532319d79c0fa5873eae325ebc12aed2a603b25
data/lib/cn/gb2260.rb ADDED
@@ -0,0 +1 @@
1
+ require 'gb2260'
@@ -0,0 +1,35 @@
1
+ module GB2260
2
+ class Division
3
+ attr_reader :code
4
+ attr_reader :name
5
+
6
+ def initialize(code)
7
+ @code = code.to_i
8
+ @name = GB2260[code].fetch(:name)
9
+ end
10
+
11
+ def province?
12
+ @code.modulo(10_000).zero?
13
+ end
14
+
15
+ def prefecture?
16
+ @code.modulo(100).zero? and not province?
17
+ end
18
+
19
+ def county?
20
+ @code.modulo(100).positive?
21
+ end
22
+
23
+ def parent
24
+ unless province?
25
+ self.class.new(@code.floor(county? ? -2 : -4))
26
+ end
27
+ end
28
+
29
+ def children
30
+ GB2260.divisions.select do |division|
31
+ division.parent&.code.eql?(@code)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module GB2260
2
+ VERSION = '1.0.1'
3
+ end
data/lib/gb2260.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'json'
2
+ require 'pathname'
3
+
4
+ require 'gb2260/version'
5
+ require 'gb2260/division'
6
+
7
+ module GB2260
8
+ @@store = {}
9
+
10
+ module_function
11
+
12
+ def [](code)
13
+ {
14
+ code: code.to_i,
15
+ name: @@store[code.to_s]
16
+ }
17
+ end
18
+
19
+ def divisions
20
+ @@store.keys.map { |code| Division.new(code) }
21
+ end
22
+
23
+ def load_file!(path)
24
+ @@store = JSON.load(Pathname(path).read)
25
+ end
26
+
27
+ class << self
28
+ alias_method :all, :divisions
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cn-gb2260
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - matark
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mercenary
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.6
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.3.6
41
+ description:
42
+ email: matark@naver.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/cn/gb2260.rb
48
+ - lib/gb2260.rb
49
+ - lib/gb2260/division.rb
50
+ - lib/gb2260/version.rb
51
+ homepage: https://opensource.matark.de/gb2260
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.0.3
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: A simple library for looking-up administrative divisions
74
+ test_files: []