GB2260 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: febcce9dda36cd75c751136957fb3f7fee0d5ef6
4
- data.tar.gz: fb00da230871eccb96690841e2c6a5050fd7c70b
3
+ metadata.gz: 6ea442b5ff290bddd262959fbfd393bd99d4566d
4
+ data.tar.gz: d59bd38a70b408ab7cce6d04979088701a5e4505
5
5
  SHA512:
6
- metadata.gz: ff25d3eefd41715e4c071b7d14f138f6e133b42bbfa51681902d543357af23dbbc2463edc7a865d6c53df83891a2314785341fef4ea3ad4eca56c6c8edcdc145
7
- data.tar.gz: 0a1b3337e5af8c1c85f17c0cd8539ed0181c986dcd09af7e494453fea5e5b4c48774bf32ab34a4120e0a0e303df403e75d778a75a1704ec166927b2046c92625
6
+ metadata.gz: f6e0f72fdb5b48a45a42c156cf603e633184c38a63c1ee1bfe3ff98be383e38b784afa7a436dfa0357cc9dbab44ac91ae304f29f9890756b9cac6ae8c2e10031
7
+ data.tar.gz: 85d70fda6f5129ff51639200cf75ebf494b21b909d4e9746ab076eb82533cedeefe109f8f2728d8d159fd3751e1dd1174332541fdce7b9a74b90fc096642a7a1
data/CHANGELOG.md CHANGED
@@ -6,12 +6,18 @@ GB2260.rb is in a pre-1.0 state. This means that its APIs and behavior are subje
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
- * Your contribution here!
9
+ Your contribution here!
10
+
11
+ ## 0.2.1 (2016-01-05)
12
+
13
+ * Return nil when the division is inexistent (https://github.com/cn/GB2260.rb/pull/4)
14
+ * Improve child divisions query performance (https://github.com/cn/GB2260.rb/pull/8)
15
+ * Add `#description` method to return human readable description (https://github.com/cn/GB2260.rb/pull/7)
10
16
 
11
17
  ## 0.2.0 (2015-11-11)
12
18
 
13
- * Implement spec 0.2
14
- * Deprecate `#year` of `Division`
19
+ * Implement spec 0.2 (https://github.com/cn/GB2260/blob/v0.2/spec.md)
20
+ * Deprecate `#year` of `Division`
15
21
 
16
22
  ## 0.1.1 (2015-09-12)
17
23
 
@@ -22,4 +28,4 @@ GB2260.rb is in a pre-1.0 state. This means that its APIs and behavior are subje
22
28
  * Initial release
23
29
 
24
30
  [Semver]: http://semver.org
25
- [Unreleased]: https://github.com/cn/GB2260.rb/compare/v0.2.0...HEAD
31
+ [Unreleased]: https://github.com/cn/GB2260.rb/compare/v0.2.1...HEAD
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # GB2260
2
2
 
3
- [![GB/T 2260](http://img.shields.io/badge/GB%2FT-2260-blue.svg?style=flat)](https://github.com/cn/GB2260)
3
+ [![GB/T 2260](https://img.shields.io/badge/GB%2FT%202260-v0.2-blue.svg)](https://github.com/cn/GB2260/blob/v0.2/spec.md)
4
4
  [![Gem Version](https://badge.fury.io/rb/GB2260.svg)](http://badge.fury.io/rb/GB2260)
5
5
  [![Build Status](https://travis-ci.org/cn/GB2260.rb.svg?branch=master)](https://travis-ci.org/cn/GB2260.rb)
6
6
  [![Code Climate](https://codeclimate.com/github/cn/GB2260.rb/badges/gpa.svg)](https://codeclimate.com/github/cn/GB2260.rb)
7
- [![Coverage Status](https://coveralls.io/repos/wolflee/GB2260.rb/badge.svg?branch=master&service=github)](https://coveralls.io/github/wolflee/GB2260.rb?branch=master)
7
+ [![Coverage Status](https://coveralls.io/repos/wolflee/GB2260.rb/badge.svg?branch=master&service=github)](https://coveralls.io/github/cn/GB2260.rb?branch=master)
8
8
 
9
9
  The Ruby implementation for looking up the Chinese administrative divisions.
10
10
 
@@ -38,7 +38,7 @@ puts division # => <GB2260-2014 江西省/九江市/德安县>
38
38
 
39
39
  ## Contributing
40
40
 
41
- Bug reports and pull requests are welcome on GitHub at https://github.com/wolflee/GB2260.rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cn/GB2260.rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
42
42
 
43
43
  ## License
44
44
 
data/lib/GB2260.rb CHANGED
@@ -3,11 +3,8 @@ require "GB2260/constants"
3
3
  require "GB2260/deprecation"
4
4
  require "GB2260/data"
5
5
  require "GB2260/division"
6
- require "GB2260/array"
7
6
 
8
7
  class GB2260
9
- using ArrayExtensions
10
-
11
8
  def self.revisions
12
9
  Data.data.keys.reverse
13
10
  end
@@ -21,25 +18,27 @@ class GB2260
21
18
  end
22
19
 
23
20
  def all_code
24
- Data.data[@revision].keys
21
+ @all_code ||= Data.data[@revision].keys.freeze
25
22
  end
26
23
 
27
24
  def provinces
28
- Division.batch all_code.select_end_with(PROVINCE_SUFFIX), @revision
25
+ Division.batch all_code.select { |c| c.end_with? PROVINCE_SUFFIX }, @revision
29
26
  end
30
27
 
31
28
  def prefectures(province_code)
32
- Division.batch(all_code
33
- .select_start_with(province_code.to_s[0,2])
34
- .select_end_with(PREFECTURE_SUFFIX)
35
- .reject_end_with(PROVINCE_SUFFIX),
36
- @revision)
29
+ province_prefix = province_code.to_s[0,2].freeze
30
+ Division.batch(all_code.lazy
31
+ .select { |c| c.start_with? province_prefix }
32
+ .select { |c| c.end_with? PREFECTURE_SUFFIX }
33
+ .reject { |c| c.end_with? PROVINCE_SUFFIX }
34
+ .force, @revision)
37
35
  end
38
36
 
39
37
  def counties(prefecture_code)
40
- Division.batch(all_code
41
- .select_start_with(prefecture_code.to_s[0,4])
42
- .reject_end_with(PREFECTURE_SUFFIX),
43
- @revision)
38
+ prefecture_prefix = prefecture_code.to_s[0,4].freeze
39
+ Division.batch(all_code.lazy
40
+ .select { |c| c.start_with? prefecture_prefix }
41
+ .reject { |c| c.end_with? PREFECTURE_SUFFIX }
42
+ .force, @revision)
44
43
  end
45
44
  end
@@ -6,11 +6,12 @@ class GB2260
6
6
  deprecate :year, :revision
7
7
 
8
8
  def self.get(code, revision=nil)
9
- new(code, Data.search(code, revision), revision)
9
+ name = Data.search(code, revision)
10
+ name && new(code, name, revision)
10
11
  end
11
12
 
12
13
  def self.batch(codes, revision=nil)
13
- codes.map { |code| get(code, revision) }
14
+ codes.map { |code| get(code, revision) }.compact
14
15
  end
15
16
 
16
17
  def initialize(code, name, revision=nil)
@@ -27,8 +28,12 @@ class GB2260
27
28
  code == other.code && revision == other.revision
28
29
  end
29
30
 
31
+ def description(separator = '/')
32
+ [province, prefecture, county].compact.map(&:name).join(separator)
33
+ end
34
+
30
35
  def to_s
31
- "<GB2260-#{@revision} #{@code} #{[province, prefecture, county].compact.map(&:name).join('/')}>"
36
+ "<GB2260-#{revision} #{code} #{description}>"
32
37
  end
33
38
 
34
39
  def hash
@@ -1,3 +1,3 @@
1
1
  class GB2260
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: GB2260
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - WolfLee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-11 00:00:00.000000000 Z
11
+ date: 2016-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -104,7 +104,6 @@ files:
104
104
  - data/GB2260-2013.txt
105
105
  - data/GB2260-2014.txt
106
106
  - lib/GB2260.rb
107
- - lib/GB2260/array.rb
108
107
  - lib/GB2260/constants.rb
109
108
  - lib/GB2260/data.rb
110
109
  - lib/GB2260/deprecation.rb
@@ -131,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
130
  version: '0'
132
131
  requirements: []
133
132
  rubyforge_project:
134
- rubygems_version: 2.4.5.1
133
+ rubygems_version: 2.5.1
135
134
  signing_key:
136
135
  specification_version: 4
137
136
  summary: The Ruby implementation for looking up the Chinese administrative divisions.
data/lib/GB2260/array.rb DELETED
@@ -1,11 +0,0 @@
1
- module ArrayExtensions
2
- refine Array do
3
- [:select, :reject].each do |action|
4
- [:start, :end].each do |position|
5
- define_method "#{action}_#{position}_with".to_sym do |predicate|
6
- self.send(action) { |c| c.send("#{position}_with?".to_sym, predicate) }
7
- end
8
- end
9
- end
10
- end
11
- end