china_regions 1.0.2 → 1.0.3
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 +4 -4
- data/README.md +5 -7
- data/README.zh.md +4 -4
- data/app/models/city.rb +16 -1
- data/app/models/district.rb +14 -1
- data/app/models/province.rb +7 -0
- data/lib/china_regions/version.rb +1 -1
- data/lib/generators/china_regions/templates/migration.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65852eef10a092038e498c3f7eec696ad6c2598072839bf3edafbc96d52579c6
|
4
|
+
data.tar.gz: '0169f567da375fd7d4e9713fe6004991ab01b34ee0a8e4fb61f33284ee96d296'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 639f67a31cf88385fec479e174e5d25999c8ee2f4e61fdac1fdf31e08012aefbfa8d5c32c40c97989dcad9629085ff656804f06d3c4931818e0158a07dd70f76
|
7
|
+
data.tar.gz: 903e20a4be9c05635e05117ace6e8e429b44d50be7938c02d7708631c4462a20c1f8a04e846a3e9cc54ccbdf8886ef1b2b0f325d8847a53d7c78ed89fd35ed47
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# ChinaRegions
|
2
2
|
|
3
|
-
[](https://badge.fury.io/rb/china_regions)
|
4
|
+
[](https://travis-ci.org/encoreshao/china_regions)
|
5
|
+
[](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
|
-
-
|
81
|
+
- Downloading regions from `Administrative-divisions-of-China` to `db/regions` folder.
|
82
82
|
- db/regions/pca-code.json
|
83
|
-
-
|
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.
|
data/README.zh.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# ChinaRegions
|
2
2
|
|
3
|
-
[](https://badge.fury.io/rb/china_regions)
|
4
|
+
[](https://travis-ci.org/encoreshao/china_regions)
|
5
|
+
[](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
|
|
data/app/models/city.rb
CHANGED
@@ -1,11 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class City < ApplicationRecord
|
4
|
-
|
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
|
data/app/models/district.rb
CHANGED
@@ -1,10 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class District < ApplicationRecord
|
4
|
-
|
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
|
data/app/models/province.rb
CHANGED
@@ -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
|
@@ -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
|