china_regions 1.0.2 → 1.0.3

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
  SHA256:
3
- metadata.gz: fc32c13b4a0595a59e167d71b409a6c3798a0d1e60559583bd7d36632ef51d96
4
- data.tar.gz: b7800a8a8c059fc7c4d596ccf576cb92379f336012275008371e810f3956ffef
3
+ metadata.gz: 65852eef10a092038e498c3f7eec696ad6c2598072839bf3edafbc96d52579c6
4
+ data.tar.gz: '0169f567da375fd7d4e9713fe6004991ab01b34ee0a8e4fb61f33284ee96d296'
5
5
  SHA512:
6
- metadata.gz: e729654e0c592fee2f8ddee5ab8241876eb076d86aa8d46d925d4984e82b141be0f449ce7cd86fd6debe55349f0eff47b007a261ce75242b66aa8f6b1ae882ff
7
- data.tar.gz: a455db27261039b7f2f7c72e1644467110856cb03376bfae8d087557ced0f6e6523c8d160e49e191ed43e026325e02696f508b9cede6a51a20838b699af9f115
6
+ metadata.gz: 639f67a31cf88385fec479e174e5d25999c8ee2f4e61fdac1fdf31e08012aefbfa8d5c32c40c97989dcad9629085ff656804f06d3c4931818e0158a07dd70f76
7
+ data.tar.gz: 903e20a4be9c05635e05117ace6e8e429b44d50be7938c02d7708631c4462a20c1f8a04e846a3e9cc54ccbdf8886ef1b2b0f325d8847a53d7c78ed89fd35ed47
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # ChinaRegions
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/crunchbase-ruby-library.svg)](https://badge.fury.io/rb/crunchbase-ruby-library)
4
- [![Build Status](https://travis-ci.org/encoreshao/crunchbase-ruby-library.svg?branch=master)](https://travis-ci.org/encoreshao/crunchbase-ruby-library)
5
- [![Coverage Status](https://coveralls.io/repos/github/encoreshao/crunchbase-ruby-library/badge.svg)](https://coveralls.io/github/encoreshao/crunchbase-ruby-library)
3
+ [![Gem Version](https://badge.fury.io/rb/china_regions.svg)](https://badge.fury.io/rb/china_regions)
4
+ [![Build Status](https://travis-ci.org/encoreshao/china_regions.svg?branch=master)](https://travis-ci.org/encoreshao/china_regions)
5
+ [![Coverage Status](https://coveralls.io/repos/github/encoreshao/china_regions/badge.svg)](https://coveralls.io/github/encoreshao/china_regions)
6
6
 
7
7
  ChinaRegions provides Ruby on Rails code for provinces, cities, and districts [prefecture-level cities] in China. The code need to requires Ruby (> 1.9.x) and Rails (> 4.0).
8
8
 
@@ -78,9 +78,9 @@ rake china_regions:download
78
78
  rake china_regions:import
79
79
  ```
80
80
 
81
- - 1. Downloading regions from `Administrative-divisions-of-China` to `db/regions` folder.
81
+ - Downloading regions from `Administrative-divisions-of-China` to `db/regions` folder.
82
82
  - db/regions/pca-code.json
83
- - 2. Import the regions into provinces and cities, districts
83
+ - Import the regions into provinces and cities, districts
84
84
 
85
85
  ### Usage
86
86
 
@@ -136,7 +136,6 @@ Prior choice:
136
136
  }
137
137
  ```
138
138
 
139
-
140
139
  ### Other languages
141
140
 
142
141
  - [Chinese](https://github.com/encoreshao/china_regions/blob/master/README.zh.md)
@@ -145,7 +144,6 @@ Prior choice:
145
144
 
146
145
  We have a list of valued contributors. Check them all at: https://github.com/encoreshao/china_regions/graphs/contributors
147
146
 
148
-
149
147
  ### License
150
148
 
151
149
  Copyright © 2020-02 Encore Shao. See LICENSE for details.
@@ -1,8 +1,8 @@
1
1
  # ChinaRegions
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/china-regions.svg)](https://badge.fury.io/rb/china-regions)
4
- [![Build Status](https://travis-ci.org/encoreshao/china-regions.svg?branch=master)](https://travis-ci.org/encoreshao/china-regions)
5
- [![Coverage Status](https://coveralls.io/repos/github/encoreshao/china-regions/badge.svg)](https://coveralls.io/github/encoreshao/china-regions)
3
+ [![Gem Version](https://badge.fury.io/rb/china_regions.svg)](https://badge.fury.io/rb/china_regions)
4
+ [![Build Status](https://travis-ci.org/encoreshao/china_regions.svg?branch=master)](https://travis-ci.org/encoreshao/china_regions)
5
+ [![Coverage Status](https://coveralls.io/repos/github/encoreshao/china_regions/badge.svg)](https://coveralls.io/github/encoreshao/china_regions)
6
6
 
7
7
  ChinaRegions 提供中国的省,市,区[地级市]的 Ruby on Rails的程式代码,代码版本要求 Ruby(> 1.9.x)和Rails(> 4.0).
8
8
 
@@ -140,7 +140,7 @@ rake china_regions:import
140
140
 
141
141
  ### 贡献者
142
142
 
143
- 你可以在这里查看到所有的代码贡献者: https://github.com/encoreshao/china_regions/graphs/contributors
143
+ 你可以在这里查看到所有的代码贡献者: https://github.com/encoreshao/china_regions/graphs/contributors
144
144
 
145
145
  ### 许可
146
146
 
@@ -1,11 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class City < ApplicationRecord
4
- belongs_to :province
4
+ # Validations
5
+ validates :code, presence: true
6
+ validates :name, presence: true, uniqueness: {
7
+ case_sensitive: false,
8
+ scope: [:province_id]
9
+ }
10
+
11
+ # Relationships
12
+ belongs_to :province, counter_cache: true
13
+ delegate :name, to: :province
14
+
5
15
  has_many :districts, dependent: :destroy
6
16
 
17
+ # Fileters
7
18
  scope :for_province, ->(province_id) { where(province_id: province_id) }
8
19
 
20
+ def full_name
21
+ [province_name, name].compact.join(' - ')
22
+ end
23
+
9
24
  def short_name
10
25
  @short_name ||= name.gsub(/市|自治州|地区|特别行政区/, '')
11
26
  end
@@ -1,10 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class District < ApplicationRecord
4
- belongs_to :city
4
+ # Validations
5
+ validates :name, presence: true, uniqueness: {
6
+ case_sensitive: false,
7
+ scope: [:city_id]
8
+ }
5
9
 
10
+ # Relationships
11
+ belongs_to :city, counter_cache: true
12
+ delegate :name, to: :city
13
+
14
+ # Filters
6
15
  scope :for_city, ->(city_id) { where(city_id: city_id) }
7
16
 
17
+ def full_name
18
+ [province.name, city_name, name].compact.join(' - ')
19
+ end
20
+
8
21
  def province
9
22
  city.province
10
23
  end
@@ -1,6 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Province < ApplicationRecord
4
+ # Validations
5
+ validates :code, presence: true
6
+ validates :name, presence: true, uniqueness: {
7
+ case_sensitive: false
8
+ }
9
+
10
+ # Relationships
4
11
  has_many :cities, dependent: :destroy
5
12
  has_many :districts, through: :cities
6
13
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ChinaRegions
4
- VERSION = '1.0.2'
4
+ VERSION = '1.0.3'
5
5
  end
@@ -13,6 +13,7 @@ class CreateChinaRegionsTables < ActiveRecord::Migration
13
13
  t.integer :code
14
14
  t.string :name_en
15
15
  t.string :name_abbr
16
+ t.integer :cities_count, default: 0
16
17
 
17
18
  t.timestamps
18
19
  end
@@ -28,6 +29,7 @@ class CreateChinaRegionsTables < ActiveRecord::Migration
28
29
  t.integer :level
29
30
  t.string :name_en
30
31
  t.string :name_abbr
32
+ t.integer :districts_count, default: 0
31
33
 
32
34
  t.timestamps
33
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: china_regions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Encore Shao