Unidom Certificate China 中国证件领域模型引擎
Unidom (UNIfied Domain Object Model) is a series of domain model engines. The China Certificate domain model engine includes Identity Card, Driving License, and Business License models. 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-certificate-china'
Run the Database Migration
rake db:migrate
The migration versions start with 2001029156.
Call the Model
identity_card = Unidom::Certificate::China::IdentityCard.identification_number_is('51010519801231123X').first_or_create(
name: 'John',
address: '#1 Nanjing Street, Shanghai, China',
issuing_authority_name: 'Shanghai Police Station',
ethnicity_code: 'HA',
validity_from_date: '2015-01-01',
validity_thru_date: '2025-01-01'
)
identity_card.gender_code # '1' male, calculated from the identification_number
identity_card.birth_date # '1980-12-31', calculated from the identification_number
# Find a business license per the 15-digit registration number
Unidom::Certificate::China::BusinessLicense.registration_number_is('510105012345670').first_or_create(
name: 'Google',
address: '#1 Nanjing Street, Shanghai, China',
issuing_authority_name: 'Shanghai Industry & Commerce Administration',
legal_representative_name: 'Lawrence Edward Page',
validity_from_date: '2015-01-01',
validity_thru_date: '2025-01-01'
)
# Find a business license per the 18-digit unified social credit identifier
Unidom::Certificate::China::BusinessLicense.unified_social_credit_identifier_is('51010501234567890X').first_or_create(
name: 'Google',
address: '#1 Nanjing Street, Shanghai, China',
issuing_authority_name: 'Shanghai Industry & Commerce Administration',
legal_representative_name: 'Lawrence Edward Page',
validity_from_date: '2015-01-01',
validity_thru_date: '2025-01-01'
)
Include the Concerns
include Unidom::Certificate::China::Concerns::AsBusinessLicenseCertificated
include Unidom::Certificate::China::Concerns::AsIdentityCardCertificated
As Business License Certificated
The As Business License Certificated do the following tasks for the includer automatically:
-
Include the As Certificated concern
-
Define the has_many :china_business_licenses macro as:
has_many :china_business_licenses, through: :certificatings, source: :certification, source_type: 'Unidom::Certificate::China::BusinessLicense'
As Identity Card Certificated
The As Identity Card Certificated do the following tasks for the includer automatically:
-
Include the As Certificated concern
-
Define the has_many :china_identity_cards macro as:
has_many :china_identity_cards, through: :certificatings, source: :certification, source_type: 'Unidom::Certificate::China::IdentityCard'
Validator
Identification Number validator
validates :identification_number, presence: true, 'unidom/certificate/china/identification_number': true
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 |options|
options[:neglected_namespaces] = %w{
Unidom::Certificate::China
}
end
RSpec examples
# spec/models/unidom_spec.rb
require 'unidom/certificate/china/models_rspec'
# spec/types/unidom_spec.rb
require 'unidom/certificate/china/types_rspec'
# spec/validators/unidom_spec.rb
require 'unidom/certificate/china/validators_rspec'