taiwan_validator 1.2.0 → 1.3.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: 69de4ab7a731a31d2e692e762418c595ff303e97
4
- data.tar.gz: ab51835610608d4ef1c85308f28504b568022962
3
+ metadata.gz: 757740928b53776a01be1ebf2fdf6e7214b374b7
4
+ data.tar.gz: 9cfe758db6cba0e2d2341a8a39bd1b2693f8e127
5
5
  SHA512:
6
- metadata.gz: 75dd21acb06a24aef524d54dd394757240713f87b0f14fde90ef994c4f08c505284ac6c1170a9762ad6ef046ffbaa7015eb2afa8eaa159917bac0679c8562b6e
7
- data.tar.gz: c14d38c2aa789893b3e7075e41ea14e406ca048401b100267ca4b992c4060d2bc0661af9ed514e67456b00b75baa7e225575d3b5b3a44d1222285b9fda5dd7fb
6
+ metadata.gz: bccb74f30d14c162d0d1a2bba16d57b96706f8ce04addbf45a94b9ddefd90effcc37cf3daaaf8c523a0e2b328929fd26a988ab09c38b0de69fd06332c4a71508
7
+ data.tar.gz: 642573c17c41a9243b7aa68e44a401e1376e1d853f6c6de060c947820459cf5e1d5329a8b4150298424c48dc420da41693660883a51004ab03bec8499c9d228b
data/README.md CHANGED
@@ -27,6 +27,8 @@ Or install it yourself as:
27
27
  ```ruby
28
28
  validates :ubn, ubn: true
29
29
  validates :id, id: true
30
+ validates :address, address: true
31
+ validates :tel, phone_number: true
30
32
  ```
31
33
 
32
34
  ## Development
@@ -1,5 +1,4 @@
1
1
  class AddressValidator < ActiveModel::EachValidator
2
- # "(?<zipcode>(^\d{5}|^\d{3})?)(?<city>\D+[縣市])(?<district>\D+?(市區|鎮區|鎮市|[鄉鎮市區]))(?<others>.+)"
3
2
  class << self
4
3
  def valid?(address)
5
4
  /(\A\d{3,5})?\s?(\D+[縣市])(\D+[鄉鎮市區])?(.+)/.match(address)
@@ -0,0 +1,13 @@
1
+ class PhoneNumberValidator < ActiveModel::EachValidator
2
+ class << self
3
+ def valid?(phone_number)
4
+ phone_number.gsub(/[\+\-\s]/, "") =~ /\A(886|0)[2-9]([0-9]{6,8})\z/
5
+ end
6
+ end
7
+
8
+ def validate_each(record, attribute, value)
9
+ unless self.class.valid?(value)
10
+ record.errors.add(attribute, options[:message] || :invalid)
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module TaiwanValidator
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -4,6 +4,7 @@ require "active_support/hash_with_indifferent_access"
4
4
  require "ubn_validator"
5
5
  require "id_validator"
6
6
  require "address_validator"
7
+ require "phone_number_validator"
7
8
 
8
9
  module TaiwanValidator
9
10
  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.2.0
4
+ version: 1.3.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-25 00:00:00.000000000 Z
11
+ date: 2015-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -99,6 +99,7 @@ files:
99
99
  - bin/setup
100
100
  - lib/address_validator.rb
101
101
  - lib/id_validator.rb
102
+ - lib/phone_number_validator.rb
102
103
  - lib/taiwan_validator.rb
103
104
  - lib/taiwan_validator/version.rb
104
105
  - lib/ubn_validator.rb