Unidom Geo China 中国地理领域模型引擎
Unidom (UNIfied Domain Object Model) is a series of domain model engines. The China Geo domain model engine includes the Region model and its migration. Unidom (统一领域对象模型)是一系列的领域模型引擎。中国地理领域模型引擎包括中国大陆的行政区划模型及其数据迁移脚本。
Recent Update
Check out the Road Map to find out what's the next. Check out the Change Log to find out what's new.
Usage in Gemfile
gem 'unidom-geo-china'
Run the Database Migration
rake db:migrate
The migration versions start with 2001049156.
Import Data
bundle exec rake unidom:geo:china:region:import file=/china-region-data/NBS-county/20141031.csv from_date=2014-10-31 scheme_id= scheme_type=
bundle exec rake unidom:geo:china:town:import file=/china-region-data/NBS-town/20141031.csv from_date=2014-10-31 scheme_id= scheme_type=
Call the Model
Unidom::Geo::China::Region.root_level # All the 31 province-level regions including Beijing, Tianjin, etc.
Unidom::Geo::China::Region.numeric_coded_as('120000').valid_at.alive.first # Tianjin (天津)
active_locations = region.locations.valid_at.alive
active_towns = region.towns.valid_at.alive
The Region model has a lot of domain knowlegde of the China regions.
region.numeric_code_middle_empty?
indicates whether theregion
is a province. 判断行政区划是否是一个省、直辖市、或者自治区。!region.numeric_code_middle_empty?&®ion.numeric_code_suffix_empty?
indicates whether theregion
is a city. 判断行政区划是否是一个地级市、地区、自治州、盟。!region..numeric_code_suffix_empty?
indicates whether theregion
is a county. 判断行政区划是否是一个自治县、县级市、旗、自治旗、市辖区、林区、特区。
- region.mducg?
indicates whether the region
is a municipality direct under central government. 判断行政区划是否是一个直辖市。
region.under_mducg?
indicates whether the region
is under any municipality direct under central government. 判断行政区划是否是一个直辖市的下级行政区划。
region.under? another_region
indicates theregion
is under the given another_region. 判断行政区划是否是一个给定行政区划的下级(含直接和间接下级)。region.super_regions
returns a scope for the super regions of theregion
. 返回找到region
直接上级行政区划的查询 scope。region.sub_regions
returns a scope for the sub regions of theregion
. 返回找到region
直接下级行政区划的查询 scope。
Include the Concerns
include Unidom::Geo::China::Concerns::AsInferiorRegion
include Unidom::Geo::China::Concerns::AsSuperiorRegion
As Inferior Region
The As Inferior Region do the following tasks for the includer automatically:
- Define the #super_regions method as:
super_regions
As Superior Region
The As Superior Region do the following tasks for the includer automatically:
- Define the #sub_regions method as:
sub_regions
Disable the Model & Migration
If you only need the app components other than models, the migrations should be neglected, and the models should not be loaded.
# config/initializers/unidom.rb
Unidom::Common.configure do ||
[:neglected_namespaces] = %w{
Unidom::Geo::China
}
end
RSpec examples
# spec/models/unidom_spec.rb
require 'unidom/geo/china/models_rspec'
# spec/types/unidom_spec.rb
require 'unidom/geo/china/types_rspec'
# spec/validators/unidom_spec.rb
require 'unidom/geo/china/validators_rspec'