taiwan_validator 1.1.0 → 1.2.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: f8274120e717b39b9ef50095a2be264d2dbb39b9
4
- data.tar.gz: 5856193a1ad24adec02746dd473f3266cc7ec293
3
+ metadata.gz: 69de4ab7a731a31d2e692e762418c595ff303e97
4
+ data.tar.gz: ab51835610608d4ef1c85308f28504b568022962
5
5
  SHA512:
6
- metadata.gz: be76ee5933a03493cb19f2f64b248e78ec2141602805231902e63b3a164e2af940151c1f1d9188f311212c6212e3768eaa3733d46a536289d7c7a0821f629772
7
- data.tar.gz: 26d6036eba49fd409d15c10792e322ebe8f216e0a4b4d36b15a506a2934d836323d37bc02147e9f85299e7a6afd74c030eed9d4060f289454a383912490ed8f0
6
+ metadata.gz: 75dd21acb06a24aef524d54dd394757240713f87b0f14fde90ef994c4f08c505284ac6c1170a9762ad6ef046ffbaa7015eb2afa8eaa159917bac0679c8562b6e
7
+ data.tar.gz: c14d38c2aa789893b3e7075e41ea14e406ca048401b100267ca4b992c4060d2bc0661af9ed514e67456b00b75baa7e225575d3b5b3a44d1222285b9fda5dd7fb
@@ -0,0 +1,14 @@
1
+ class AddressValidator < ActiveModel::EachValidator
2
+ # "(?<zipcode>(^\d{5}|^\d{3})?)(?<city>\D+[縣市])(?<district>\D+?(市區|鎮區|鎮市|[鄉鎮市區]))(?<others>.+)"
3
+ class << self
4
+ def valid?(address)
5
+ /(\A\d{3,5})?\s?(\D+[縣市])(\D+[鄉鎮市區])?(.+)/.match(address)
6
+ end
7
+ end
8
+
9
+ def validate_each(record, attribute, value)
10
+ unless self.class.valid?(value)
11
+ record.errors.add(attribute, options[:message] || :invalid)
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module TaiwanValidator
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -3,6 +3,7 @@ require "active_model"
3
3
  require "active_support/hash_with_indifferent_access"
4
4
  require "ubn_validator"
5
5
  require "id_validator"
6
+ require "address_validator"
6
7
 
7
8
  module TaiwanValidator
8
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taiwan_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Yun
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-08 00:00:00.000000000 Z
11
+ date: 2015-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -97,6 +97,7 @@ files:
97
97
  - Rakefile
98
98
  - bin/console
99
99
  - bin/setup
100
+ - lib/address_validator.rb
100
101
  - lib/id_validator.rb
101
102
  - lib/taiwan_validator.rb
102
103
  - lib/taiwan_validator/version.rb