romanianvalidators 0.1.4 → 0.1.5

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: 106793ba3003fa1e423dccb482ddb68ebe40434f
4
- data.tar.gz: 4bedcaa54fadc580cc94e94be67d926d3276042d
3
+ metadata.gz: 50f809f30c598ff70bffc2683360837c69732452
4
+ data.tar.gz: bb39cbd87e1494b6e5339250bdc3c3dd5a7673da
5
5
  SHA512:
6
- metadata.gz: 07c908f816f01e6b7da2b8b44cea6a50fd6ef90a85345014444841d390b9bb2c38dfb56f5f03c269e6083265224cb2557a61c17b1ebc42dd4173bdc011bdb473
7
- data.tar.gz: eb59ae55e08cfbed0c1af5ab7278b4d72837dc08ca7023da6182706761b799c721fc669b2b21087005e78732e90489554752036ac6ddc19e1e38528bc5a430f4
6
+ metadata.gz: 19b479580c2a090b11a03a2a94c6de981e7c977d73d08983d506ff50e8ecd54ea9d722c4826a7f26926912a7fea664f01f9d3b5a779e79af8ede6bf543830de6
7
+ data.tar.gz: c92272d645cbb299d26eecf8a45df1d130b30b9b6e7b34c76cbf1bf0187ed8e982902cdf91ae4fe4005f594a6e9eaa943134c0ea728f9dfc2904397fc019f3e9
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ romanianvalidators
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.2
data/.travis.yml CHANGED
@@ -8,3 +8,4 @@ rvm:
8
8
  - rbx-19mode
9
9
  - ruby-head
10
10
  - 2.0.0
11
+ - 2.1.2
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2007, 2012 Mihai Târnovan
1
+ Copyright (c) 2007, 2014 Mihai Târnovan
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -40,8 +40,8 @@ The algorithms for validation are found in the source code.
40
40
 
41
41
  ```ruby
42
42
  class User
43
- validates :cnp, :cnp => { :message => 'This is not a valid CNP'}
44
- validates :company_cif, :cif => true
43
+ validates :cnp, cnp: { message: 'This is not a valid CNP' }
44
+ validates :company_cif, cif: true
45
45
  end
46
46
  ```
47
47
 
@@ -52,4 +52,4 @@ The algorithms for validation are found in the source code.
52
52
 
53
53
  ### Copyright
54
54
 
55
- Copyright (c) 2007-2013 Mihai Târnovan. MIT LICENSE. See LICENSE for details.
55
+ Copyright (c) 2007-2014 Mihai Târnovan. MIT LICENSE. See LICENSE for details.
@@ -1,19 +1,25 @@
1
1
  module ActiveModel
2
2
  module Validations
3
3
  class BicValidator < EachValidator
4
-
5
4
  include ActiveModel::Validations::EmptyBlankEachValidator
6
-
5
+ COUNTRY_CODES =
6
+ %w(AF AL DZ AS AD AO AI AG AR AM AW AU AT AZ BS BH BD BB BY BE BZ BJ BM
7
+ BT BO BA BW BR BN BG BF BI KH CM CA CV KY CF TD CL CN CO KM CG CD CK CR
8
+ CI HR CU CY CZ DK DJ DM DO EC EG SV GQ ER EE ET FK FO FJ FI FR GF PF GA
9
+ GM GE DE GH GI GR GL GD GP GU GT GN GW GY HT VA HN HK HU IS IN ID IR IQ
10
+ IE IL IT JM JP JO KZ KE KI KP KR KW KG LA LV LB LS LR LY LI LT LU MO MK
11
+ MG MW MY MV ML MT MH MQ MR MU MX FM MD MC MN MS MA MZ MM NA NR NP NL AN
12
+ NC NZ NI NE NG NU NF MP NO OM PK PW PA PG PY PE PH PN PL PT PR QA RE RO
13
+ RU RW SH KN LC PM VC WS SM ST SA SN SC SL SG SK SI SB SO ZA ES LK SD SR
14
+ SJ SZ SE CH SY TW TJ TZ TH TG TK TO TT TN TR TM TC TV UG UA AE GB US UY
15
+ UZ VU VE VN VG VI WF EH YE ZM ZW)
7
16
  # This is only a basic validation of a BIC
8
17
  # http://www.swift.com/biconline/index.cfm?fuseaction=display_aboutbic
9
18
  def valid?(bic)
10
- country_codes = %w[AF AL DZ AS AD AO AI AG AR AM AW AU AT AZ BS BH BD BB BY BE BZ BJ BM BT BO BA BW BR BN BG BF BI KH CM CA CV KY CF TD CL CN CO KM CG CD CK CR CI HR CU CY CZ DK DJ DM DO EC EG SV GQ ER EE ET FK FO FJ FI FR GF PF GA GM GE DE GH GI GR GL GD GP GU GT GN GW GY HT VA HN HK HU IS IN ID IR IQ IE IL IT JM JP JO KZ KE KI KP KR KW KG LA LV LB LS LR LY LI LT LU MO MK MG MW MY MV ML MT MH MQ MR MU MX FM MD MC MN MS MA MZ MM NA NR NP NL AN NC NZ NI NE NG NU NF MP NO OM PK PW PA PG PY PE PH PN PL PT PR QA RE RO RU RW SH KN LC PM VC WS SM ST SA SN SC SL SG SK SI SB SO ZA ES LK SD SR SJ SZ SE CH SY TW TJ TZ TH TG TK TO TT TN TR TM TC TV UG UA AE GB US UY UZ VU VE VN VG VI WF EH YE ZM ZW]
11
19
  return false unless bic.size == 8 || bic.size == 11 # length 8 or 11
12
- return false unless (bic[0..3]=~(/[^A-Z]/)).nil? # first 4 must be letters only
13
- return true if country_codes.include?(bic[4..5])
14
- false
20
+ return false unless (bic[0..3] =~ (/[^A-Z]/)).nil? # first 4 must be letters only
21
+ COUNTRY_CODES.include?(bic[4..5])
15
22
  end
16
-
17
23
  end
18
24
  end
19
- end
25
+ end
@@ -3,7 +3,7 @@ module ActiveModel
3
3
  class CifValidator < EachValidator
4
4
 
5
5
  # reversed test key (753217532)
6
- TEST_KEY = "235712357".freeze
6
+ TEST_KEY = '235712357'.freeze
7
7
 
8
8
  include ActiveModel::Validations::EmptyBlankEachValidator
9
9
 
@@ -20,30 +20,29 @@ module ActiveModel
20
20
  # pozitia treisprezece din CNP-ul initial.
21
21
  def valid?(cnp)
22
22
  return false unless well_formed?(cnp) && valid_birthdate?(cnp)
23
-
24
23
  (0..11).inject(0){|sum, n| sum += TEST_KEY[n].chr.to_i * cnp[n].chr.to_i} % 11 == cnp[12].chr.to_i
25
24
  end
26
25
 
27
- private
26
+ private
28
27
 
29
- def well_formed?(cnp)
30
- (cnp=~(/[^0-9]/)).nil? && cnp.size == 13
31
- end
28
+ def well_formed?(cnp)
29
+ (cnp =~ (/[^0-9]/)).nil? && cnp.size == 13
30
+ end
32
31
 
33
- def valid_birthdate?(cnp)
34
- year_code = cnp[0].chr.to_i
35
- year = case year_code
36
- when 1..2 then "19"
37
- when 3..4 then "18"
38
- when 5..6 then "20"
39
- when 9 then "19" # oare se sare peste un an bisect intre 1800-2099 ?
40
- else return false
41
- end
42
- year = (year + cnp[1..2]).to_i
43
- Date.valid_civil?(year, cnp[3..4].to_i, cnp[5..6].to_i) ? true : false
44
- rescue ArgumentError
45
- return false
46
- end
32
+ def valid_birthdate?(cnp)
33
+ year_code = cnp[0].chr.to_i
34
+ year = case year_code
35
+ when 1..2 then "19"
36
+ when 3..4 then "18"
37
+ when 5..6 then "20"
38
+ when 9 then "19" # oare se sare peste un an bisect intre 1800-2099 ?
39
+ else return false
40
+ end
41
+ year = (year + cnp[1..2]).to_i
42
+ Date.valid_civil?(year, cnp[3..4].to_i, cnp[5..6].to_i) ? true : false
43
+ rescue ArgumentError
44
+ return false
45
+ end
47
46
 
48
47
  end
49
48
  end
@@ -3,7 +3,7 @@ module ActiveModel
3
3
  class IbanValidator < EachValidator
4
4
 
5
5
  # use ord for ruby >= 1.9
6
- USE_ORD = "".respond_to?(:ord)
6
+ USE_ORD = ''.respond_to?(:ord)
7
7
 
8
8
  include ActiveModel::Validations::EmptyBlankEachValidator
9
9
 
@@ -16,16 +16,15 @@ module ActiveModel
16
16
  false
17
17
  end
18
18
 
19
- private
19
+ private
20
20
 
21
- # replace letters according to algorithm
22
- # algorithm conversion maps chars to ASCII value - 55
23
- def transpose(iban)
24
- iban.upcase.gsub(/[A-Z]/) do |s|
25
- USE_ORD ? (s[0].ord - 55).to_s : (s[0].to_i - 55).to_s
26
- end
21
+ # replace letters according to algorithm
22
+ # algorithm conversion maps chars to ASCII value - 55
23
+ def transpose(iban)
24
+ iban.upcase.gsub(/[A-Z]/) do |s|
25
+ USE_ORD ? (s[0].ord - 55).to_s : (s[0].to_i - 55).to_s
27
26
  end
28
-
27
+ end
29
28
  end
30
29
  end
31
- end
30
+ end
@@ -10,10 +10,10 @@ module ActiveModel
10
10
  def validate_each(record, attribute, value)
11
11
  allow_blank = options.fetch(:allow_blank, false)
12
12
  allow_nil = options.fetch(:allow_nil, false)
13
- message = options.fetch(:message, nil)
14
- record.errors.add_on_empty(attribute) if value.nil? && !allow_nil
15
- record.errors.add_on_blank(attribute) if value.blank? && !allow_blank
16
- record.errors.add(attribute, message) unless valid?(value)
13
+ message = options.fetch(:message, :invalid)
14
+ record.errors.add_on_empty(attribute) && return if value.nil? && !allow_nil
15
+ record.errors.add_on_blank(attribute) && return if value.blank? && !allow_blank
16
+ record.errors.add(attribute, message) && return unless valid?(value)
17
17
  end
18
18
  end
19
19
 
@@ -24,8 +24,8 @@ module ActiveModel
24
24
  module HelperMethods
25
25
  ActiveModel::Validations.romanianvalidators.each do |validator|
26
26
  define_method('validates_' + validator) do |*fields|
27
- options ||= (fields.delete fields.find { |f| f.kind_of? Hash}) || true
28
- args = fields.push({ validator => options })
27
+ options ||= (fields.delete(fields.find { |f| f.is_a? Hash })) || true
28
+ args = fields.push(validator => options)
29
29
  validates(*args)
30
30
  end
31
31
  end
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'romanianvalidators'
4
- s.version = '0.1.4'
4
+ s.version = '0.1.5'
5
5
  s.authors = ['Mihai Târnovan']
6
6
  s.email = ['mihai.tarnovan@cubus.ro']
7
7
  s.homepage = 'http://github.com/mtarnovan/romanianvalidators'
data/test/test_helper.rb CHANGED
@@ -11,6 +11,9 @@ require 'minitest/autorun'
11
11
  $-w = old_w
12
12
 
13
13
  require 'romanianvalidators'
14
+ require 'active_support/core_ext/array/wrap'
15
+
16
+ I18n.enforce_available_locales = true
14
17
 
15
18
  class TestRecord
16
19
  include ActiveModel::Validations
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: romanianvalidators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mihai Târnovan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-29 00:00:00.000000000 Z
11
+ date: 2014-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.8.7
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.8.7
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activemodel
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: 3.0.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.0.0
69
69
  description: Collection of validations for Cod Numeric Personal (CNP), Cod de identificare
@@ -75,8 +75,10 @@ executables: []
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
77
  files:
78
- - .gitignore
79
- - .travis.yml
78
+ - ".gitignore"
79
+ - ".ruby-gemset"
80
+ - ".ruby-version"
81
+ - ".travis.yml"
80
82
  - CHANGELOG.md
81
83
  - Gemfile
82
84
  - LICENSE
@@ -107,17 +109,17 @@ require_paths:
107
109
  - lib
108
110
  required_ruby_version: !ruby/object:Gem::Requirement
109
111
  requirements:
110
- - - '>='
112
+ - - ">="
111
113
  - !ruby/object:Gem::Version
112
114
  version: '0'
113
115
  required_rubygems_version: !ruby/object:Gem::Requirement
114
116
  requirements:
115
- - - '>='
117
+ - - ">="
116
118
  - !ruby/object:Gem::Version
117
119
  version: '0'
118
120
  requirements: []
119
121
  rubyforge_project: romanianvalidators
120
- rubygems_version: 2.0.0
122
+ rubygems_version: 2.2.2
121
123
  signing_key:
122
124
  specification_version: 4
123
125
  summary: Collection of validations for Cod Numeric Personal (CNP), Cod de identificare