unidom-certificate-china 0.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9f951709eabad4e2442dc82ab2bb324c82cd81a
4
- data.tar.gz: 1bc1a62bb5e6a1a3c03170366723dbb29b416749
3
+ metadata.gz: 367cb07f19c0240c362f2850ca519e2f033112f9
4
+ data.tar.gz: 4f5a4896ca07d4c9e213c35c068f2d5a26a31574
5
5
  SHA512:
6
- metadata.gz: d390d1831f2310a171c7ac0d7fb597a97523db97eba2f8c77b1287afab97c480160a1246f7a468253727db83be0af253019e316cdfa6fba7720e20f5abf12578
7
- data.tar.gz: c968987d31b11fe838e0cd083848a2f76ddb7af43d593a1a44f25041099cbc7a9a4c3f11b84f17e66e1167417fa823d0489f97dc98e85197915c2af41cb20d1f
6
+ metadata.gz: 1580a74418a880324a8af138257b47db22844a68bb8c3556f89ff4cd6c2ac9bcfda7fc7ca4c89bfe42e525ea13f46e0e9e4351d7e6384978f71094d4d31700b8
7
+ data.tar.gz: 40d22ab278ab589e093a1e38faf06eb3d997eafde6d19a03c4638a757ddbbdff6706318bc7d10b3286d0ed8f17ac8dc2ae66bed8298af4578c1acc5606e1dbff
data/README.md CHANGED
@@ -18,5 +18,14 @@ rake db:migrate
18
18
 
19
19
  ## Call the Model
20
20
  ```ruby
21
- Unidom::Certificate::China::IdentityCard.identification_number_is('51010519801231123X').first
21
+ identity_card = Unidom::Certificate::China::IdentityCard.identification_number_is('51010519801231123X').first_or_create(
22
+ name: 'John',
23
+ address: '#1 Nanjing Street, Shanghai, China',
24
+ issuing_authority_name: 'Shanghai Police Station',
25
+ ethnicity_code: 'HA',
26
+ validity_from_date: '2015-01-01',
27
+ validity_thru_date: '2025-01-01'
28
+ )
29
+ identity_card.gender_code # '1' male, calculated from the identification_number
30
+ identity_card.birth_date # '1980-12-31', calculated from the identification_number
22
31
  ```
@@ -4,9 +4,11 @@ class Unidom::Certificate::China::IdentityCard < ActiveRecord::Base
4
4
 
5
5
  self.table_name = 'unidom_china_identity_cards'
6
6
 
7
+ FORMAT_VALIDATION_REGEX = /\A\d{17}[\dx]\z/i
8
+
7
9
  validates :name, presence: true, length: { in: 2..self.columns_hash['name'].limit }
8
10
  validates :address, presence: true, length: { in: 2..self.columns_hash['address'].limit }
9
- validates :identification_number, presence: true, length: { is: self.columns_hash['identification_number'].limit }
11
+ validates :identification_number, presence: true, length: { is: self.columns_hash['identification_number'].limit }, format: FORMAT_VALIDATION_REGEX
10
12
  validates :issuing_authority_name, presence: true, length: { in: 2..self.columns_hash['issuing_authority_name'].limit }
11
13
 
12
14
  has_many :certificatings, class_name: 'Unidom::Certificate::Certificating', as: :certification
@@ -15,9 +17,9 @@ class Unidom::Certificate::China::IdentityCard < ActiveRecord::Base
15
17
 
16
18
  include Unidom::Common::Concerns::ModelExtension
17
19
 
18
- before_validation -> {
20
+ before_validation do
19
21
  self.birth_date = Date.parse "#{identification_number[6..9]}-#{identification_number[10..11]}-#{identification_number[12..13]}"
20
22
  self.gender_code = identification_number[16].to_i.odd? ? '1' : '2'
21
- }
23
+ end
22
24
 
23
25
  end
@@ -1,7 +1,7 @@
1
1
  module Unidom
2
2
  module Certificate
3
3
  module China
4
- VERSION = '0.2'.freeze
4
+ VERSION = '0.3'.freeze
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-certificate-china
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-25 00:00:00.000000000 Z
11
+ date: 2016-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: unidom-certificate
14
+ name: unidom-common
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.1'
19
+ version: '0.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.1'
26
+ version: '0.5'
27
27
  description: Unidom (UNIfied Domain Object Model) is a series of domain model engines.
28
28
  The China Certificate domain model engine includes Identity Card, Driving License,
29
29
  and Business License models. Unidom (统一领域对象模型)是一系列的领域模型引擎。中国证件领域模型引擎包括中国大陆的身份证、驾驶证、营业执照等模型。