unidom-region-china 0.1 → 1.0

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: e74b75d5ef9c0aa9e94a8977e764c0a1abeecfb6
4
- data.tar.gz: 2cd4094801e33d047957f47c7ef78fccac8fb50b
3
+ metadata.gz: e46a6679bd74407ba119f1e828fd9a3691bf28e7
4
+ data.tar.gz: 7fa84735cbd1107bc7b8c18c1abacad6efe7cd78
5
5
  SHA512:
6
- metadata.gz: dbf52066e80a9b78d2d3966895d8ff83ede28ea25edff7b4d6d4e744b8dce4014ff4312c2f460004d028cde3e95657b5730f8cf53e227b367b7cb542b53a1b64
7
- data.tar.gz: 2c6d6f1d4c7d463991f89e44e13bd212667320d7b6916669e2885d52117aca99544862e80757b14162c27912e65c741461b0d2e634eb192ec114eebc9d5bb58c
6
+ metadata.gz: 52112ed8fe01dad17dd0ca80f4a0633f5e83cb2fe65271371ae93ca7360448270e38322471fe141db6ae6b3fa4ea7c180eaf4613dabdb99ddb9b3d1a0a5ab003
7
+ data.tar.gz: 3205bb2ab03c3d9470a8628674b81217101289c77c506c5db57bbb2d059601a37d7b81e58ed29af636b6a7ceb2c64d423ff8a46cc90ea9f06ad5f6c7daa8b9e4
data/README.md CHANGED
@@ -7,11 +7,17 @@ Unidom (统一领域对象模型)是一系列的领域模型引擎。中国行
7
7
  ```ruby
8
8
  gem 'unidom-region-china'
9
9
  ```
10
+
10
11
  ## Run the Database Migration:
11
12
  ```shell
12
13
  rake db:migrate
13
14
  ```
14
15
 
16
+ ## Import Data:
17
+ ```shell
18
+ bundle exec rake unidom:region:china:import file=/china-region-data/NBS-county/20141031.csv from_date=2014-10-31 scheme_id= scheme_type=
19
+ ```
20
+
15
21
  ## Call the Model:
16
22
  ```ruby
17
23
  Unidom::Region::China::Region.numeric_coded_as('120000').valid_at.alive.first # Tianjing (天津)
@@ -29,12 +29,12 @@ class Unidom::Region::China::Region < ActiveRecord::Base
29
29
  validates :alphabetic_code, allow_blank: true, length: { minimum: 2 }
30
30
  validates :name, presence: true, length: { maximum: self.columns_hash['name'].limit }
31
31
 
32
- belongs_to :schema, polymorphic: true
32
+ belongs_to :scheme, polymorphic: true
33
33
  has_many :locations, class_name: 'Unidom::Geo::Location', as: :region
34
34
 
35
- scope :schema_is, ->(schema) { schema.present? ? where(schema: schema) : schema_id_is.schema_type_is }
36
- scope :schema_id_is, ->(schema_id = ::Unidom::Common::NULL_UUID) { where schema_id: schema_id }
37
- scope :schema_type_is, ->(schema_type = '' ) { where schema_type: schema_type }
35
+ scope :scheme_is, ->(scheme) { scheme.present? ? where(scheme: scheme) : scheme_id_is.scheme_type_is }
36
+ scope :scheme_id_is, ->(scheme_id = ::Unidom::Common::NULL_UUID) { where scheme_id: scheme_id }
37
+ scope :scheme_type_is, ->(scheme_type = '' ) { where scheme_type: scheme_type }
38
38
 
39
39
  scope :name_is, ->(name) { where name: name }
40
40
  scope :being_virtual, ->(virtual = true) { where virtual: virtual }
@@ -4,7 +4,7 @@ class CreateUnidomChinaRegions < ActiveRecord::Migration
4
4
 
5
5
  create_table :unidom_china_regions, id: :uuid do |t|
6
6
 
7
- t.references :schema, type: :uuid, null: false,
7
+ t.references :scheme, type: :uuid, null: false,
8
8
  polymorphic: { null: false, default: '', limit: 200 }
9
9
 
10
10
  t.column :numeric_code, 'char(6)', null: false, default: '0'*6
@@ -26,9 +26,9 @@ class CreateUnidomChinaRegions < ActiveRecord::Migration
26
26
 
27
27
  end
28
28
 
29
- add_index :unidom_china_regions, :schema_id
30
- add_index :unidom_china_regions, [ :numeric_code, :schema_id, :schema_type ], unique: true, name: 'index_unidom_china_regions_on_numeric_code_and_schema'
31
- add_index :unidom_china_regions, [ :alphabetic_code, :schema_id, :schema_type ], unique: true, name: 'index_unidom_china_regions_on_alphabetic_code_and_schema'
29
+ add_index :unidom_china_regions, :scheme_id
30
+ add_index :unidom_china_regions, [ :numeric_code, :scheme_id, :scheme_type ], unique: true, name: 'index_unidom_china_regions_on_numeric_code_and_scheme'
31
+ add_index :unidom_china_regions, [ :alphabetic_code, :scheme_id, :scheme_type ], unique: true, name: 'index_unidom_china_regions_on_alphabetic_code_and_scheme'
32
32
 
33
33
  end
34
34
 
@@ -7,28 +7,28 @@ namespace :unidom do
7
7
  # bundle exec rake unidom:region:china:import
8
8
  # file=/data.csv
9
9
  # from_date=2020-01-01
10
- # schema_id=
11
- # schema_type=
10
+ # scheme_id=
11
+ # scheme_type=
12
12
  task import: :environment do
13
13
 
14
14
  include ::Unidom::Common::DataHelper
15
15
 
16
16
  file_name = ENV['file']
17
- schema_id = ENV['schema_id']||::Unidom::Common::NULL_UUID
18
- schema_type = ENV['schema_type']||''
17
+ scheme_id = ENV['scheme_id']||::Unidom::Common::NULL_UUID
18
+ scheme_type = ENV['scheme_type']||''
19
19
  opened_at = parse_time ENV['from_date']
20
20
 
21
21
  updated_count = 0
22
22
  created_count = 0
23
23
 
24
- region_entities = ::Unidom::Region::China::Region.schema_id_is(schema_id).schema_type_is(schema_type).select('id, name, virtual, numeric_code, alphabetic_code, schema_id, schema_type, opened_at, closed_at, defunct, updated_at').to_a
24
+ region_entities = ::Unidom::Region::China::Region.scheme_id_is(scheme_id).scheme_type_is(scheme_type).select('id, name, virtual, numeric_code, alphabetic_code, scheme_id, scheme_type, opened_at, closed_at, defunct, updated_at').to_a
25
25
 
26
26
  each_csv_row file_name do |region|
27
27
 
28
28
  numeric_code = region['numeric_code']
29
29
  alphabetic_code = region['alphabetic_code']
30
30
 
31
- attributes = { name: region['name'], virtual: region['virtual'], schema_id: schema_id, schema_type: schema_type, opened_at: opened_at }
31
+ attributes = { name: region['name'], virtual: region['virtual'], scheme_id: scheme_id, scheme_type: scheme_type, opened_at: opened_at }
32
32
  attributes[:alphabetic_code] = alphabetic_code if alphabetic_code.present?
33
33
 
34
34
  if region_entities.present?
@@ -1,7 +1,7 @@
1
1
  module Unidom
2
2
  module Region
3
3
  module China
4
- VERSION = '0.1'.freeze
4
+ VERSION = '1.0'.freeze
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-region-china
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '1.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du