bank_card 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,12 +2,17 @@ module BankCard
2
2
  module Validations
3
3
  class LuhnValidator < ActiveModel::EachValidator
4
4
  def validate_each(record, attribute, value)
5
+ if value !~ /\A\d+\Z/
6
+ record.errors.add(attribute, :invalid, options)
7
+ return
8
+ end
9
+
5
10
  relative_number = {'0' => 0, '1' => 2, '2' => 4, '3' => 6, '4' => 8, '5' => 1, '6' => 3, '7' => 5, '8' => 7, '9' => 9}
6
11
 
7
12
  sum = 0
8
13
 
9
14
  value.to_s.reverse.split("").each_with_index do |n, i|
10
- sum += (i % 2 == 0) ? n.to_i : relative_number[n]
15
+ sum += (i % 2 == 0) ? n.to_i : relative_number[n]
11
16
  end
12
17
 
13
18
  unless sum % 10 == 0
@@ -1,3 +1,3 @@
1
1
  module BankCard
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -16,6 +16,7 @@ describe CreditCard do
16
16
  describe "number with Luhn algorithm" do
17
17
  before { CreditCard.validates :number, :luhn => true }
18
18
 
19
+ it { should_not allow_value('hello').for(:number) }
19
20
  it { should_not allow_value('123').for(:number) }
20
21
  it { should allow_value('4200000000000000').for(:number) }
21
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bank_card
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-22 00:00:00.000000000Z
12
+ date: 2012-06-21 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2153585680 !ruby/object:Gem::Requirement
16
+ requirement: &2161006180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2153585680
24
+ version_requirements: *2161006180
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: guard
27
- requirement: &2153585220 !ruby/object:Gem::Requirement
27
+ requirement: &2161005760 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2153585220
35
+ version_requirements: *2161005760
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: guard-rspec
38
- requirement: &2153584680 !ruby/object:Gem::Requirement
38
+ requirement: &2161005320 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2153584680
46
+ version_requirements: *2161005320
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard-bundler
49
- requirement: &2153584140 !ruby/object:Gem::Requirement
49
+ requirement: &2161004860 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2153584140
57
+ version_requirements: *2161004860
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: ruby-debug19
60
- requirement: &2153583720 !ruby/object:Gem::Requirement
60
+ requirement: &2161004360 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2153583720
68
+ version_requirements: *2161004360
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: shoulda-matchers
71
- requirement: &2153582420 !ruby/object:Gem::Requirement
71
+ requirement: &2161003820 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2153582420
79
+ version_requirements: *2161003820
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: timecop
82
- requirement: &2153562380 !ruby/object:Gem::Requirement
82
+ requirement: &2161003200 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2153562380
90
+ version_requirements: *2161003200
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: activemodel
93
- requirement: &2153561820 !ruby/object:Gem::Requirement
93
+ requirement: &2161002560 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *2153561820
101
+ version_requirements: *2161002560
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: activesupport
104
- requirement: &2153561340 !ruby/object:Gem::Requirement
104
+ requirement: &2161002000 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: '0'
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *2153561340
112
+ version_requirements: *2161002000
113
113
  description: Gem includes validations, card brand detection method, etc.
114
114
  email:
115
115
  - alovak@gmail.com