valigator-csv 1.3.0 → 1.3.1

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: 36b7a576342bf50503a9116df95032cb815a88e9
4
- data.tar.gz: 55257cf5e9b02ea0c66820279fdbc2caad6270e6
3
+ metadata.gz: 3603756bf634bc260cf48f545f60775106fd7dd5
4
+ data.tar.gz: 363ddd31daac8f72f47ba0b3db1f3a6db44df74b
5
5
  SHA512:
6
- metadata.gz: d41045648d6d141622f6d0b9bd4d48330af1e2e3e8a10c8d5dc141b8cb6047232443a4f3d62064bef15dd8e80ecfcda037d35bccadd050754ac7314ad6cd2240
7
- data.tar.gz: 077b6fc2fc0bec290557ea9b2860cebef2cd2e94c3888ffcb3c0bd75dc2bc6e4003e611494b538a27ffe2cfb46117d7d180de0a6a8f73d7992907f4099bac6fa
6
+ metadata.gz: c3886a84957480ad2169738266d259406e6f76083c3fda709d720746b59e351343f0423553cb3fbb8489fd17b1950b302682acae53a96e120926cb1e74383a79
7
+ data.tar.gz: 1ad3987358197d2362fe411dedb7102166973664063ec15f2e8256b70baba9925da2724f82213b99378a425c226fc1e55a43bade28ad7de8ff7abf66aa3cb48a
@@ -0,0 +1,52 @@
1
+ module Valigator
2
+ module CSV
3
+ module FieldValidators
4
+ class Base
5
+ attr_reader :options
6
+
7
+ def initialize(options={})
8
+ @options = options
9
+ end
10
+
11
+
12
+
13
+ def valid?(value)
14
+ raise NotImplementedError
15
+ end
16
+
17
+
18
+
19
+ def error_type
20
+ raise NotImplementedError
21
+ end
22
+
23
+
24
+
25
+ def error_message
26
+ raise NotImplementedError
27
+ end
28
+
29
+
30
+
31
+ def ==(other)
32
+ self.class == other.class && options == other.options
33
+ end
34
+
35
+
36
+
37
+ private
38
+
39
+ def blank?(value)
40
+ value.to_s.empty?
41
+ end
42
+
43
+
44
+
45
+ def allow_blank
46
+ options[:allow_blank]
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,16 +1,12 @@
1
1
  module Valigator
2
2
  module CSV
3
3
  module FieldValidators
4
- class Date
5
-
6
- def initialize(options={})
7
- @options = options
8
- end
9
-
10
-
4
+ class Date < Base
11
5
 
12
6
  def valid?(value)
13
- format ? ::Date.strptime(value, format) : ::Date.parse(value)
7
+ return true if allow_blank and blank? value
8
+
9
+ parse value
14
10
  true
15
11
  rescue ArgumentError
16
12
  false
@@ -36,6 +32,12 @@ module Valigator
36
32
  @options[:format]
37
33
  end
38
34
 
35
+
36
+
37
+ def parse(value)
38
+ format ? ::Date.strptime(value.to_s, format) : ::Date.parse(value.to_s)
39
+ end
40
+
39
41
  end
40
42
  end
41
43
  end
@@ -3,16 +3,10 @@ module Valigator
3
3
  module FieldValidators
4
4
  class Float < Integer
5
5
 
6
- def initialize(options = {})
7
- @options = options
8
- end
9
-
10
-
11
-
12
6
  def valid?(value)
13
7
  formatted = formatted_value(value)
14
8
 
15
- formatted.to_f.to_s == formatted || super
9
+ super || value.is_a?(::Float) || formatted.to_f.to_s == formatted
16
10
  end
17
11
 
18
12
 
@@ -38,7 +32,7 @@ module Valigator
38
32
 
39
33
 
40
34
  def formatted_value(value)
41
- decimal_mark ? value.gsub(decimal_mark, '.') : value
35
+ decimal_mark ? value.to_s.gsub(decimal_mark, '.') : value
42
36
  end
43
37
 
44
38
 
@@ -1,12 +1,12 @@
1
1
  module Valigator
2
2
  module CSV
3
3
  module FieldValidators
4
- class Integer
4
+ class Integer < Base
5
5
 
6
6
  def valid?(value)
7
- return true if value.to_s.empty?
7
+ return true if allow_blank and blank? value
8
8
 
9
- value.to_i.to_s == value.to_s
9
+ value.is_a?(::Integer) || value.to_i.to_s == value.to_s
10
10
  end
11
11
 
12
12
 
@@ -1,10 +1,10 @@
1
1
  module Valigator
2
2
  module CSV
3
3
  module FieldValidators
4
- class Mandatory
4
+ class Mandatory < Base
5
5
 
6
6
  def valid?(value)
7
- !value.to_s.empty?
7
+ not blank? value
8
8
  end
9
9
 
10
10
 
@@ -18,6 +18,7 @@ module Valigator
18
18
  def error_message
19
19
  'Missing mandatory field'
20
20
  end
21
+
21
22
  end
22
23
  end
23
24
  end
@@ -1,6 +1,7 @@
1
1
  module Valigator
2
2
  module CSV
3
3
  module FieldValidators
4
+ autoload :Base, 'valigator/csv/field_validators/base'
4
5
  autoload :Date, 'valigator/csv/field_validators/date'
5
6
  autoload :Float, 'valigator/csv/field_validators/float'
6
7
  autoload :Integer, 'valigator/csv/field_validators/integer'
@@ -1,5 +1,5 @@
1
1
  module Valigator
2
2
  module CSV
3
- VERSION = "1.3.0"
3
+ VERSION = "1.3.1"
4
4
  end
5
5
  end
@@ -6,8 +6,8 @@ require 'valigator/csv/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'valigator-csv'
8
8
  spec.version = Valigator::CSV::VERSION
9
- spec.authors = ['Daniel Nagy', 'Istvan Demeter']
10
- spec.email = ['naitodai@gmail.com', 'demeter.istvan@gmail.com']
9
+ spec.authors = ['Daniel Nagy', 'Istvan Demeter', 'Tamas Drahos']
10
+ spec.email = ['naitodai@gmail.com', 'demeter.istvan@gmail.com', 'drahostamas@gmail.com']
11
11
 
12
12
  spec.summary = %q{Yet another CSV validator library}
13
13
  spec.description = %q{Yet another CSV validator library. Just better.}
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valigator-csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Nagy
8
8
  - Istvan Demeter
9
+ - Tamas Drahos
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2015-12-08 00:00:00.000000000 Z
13
+ date: 2015-12-10 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: bundler
@@ -57,6 +58,7 @@ description: Yet another CSV validator library. Just better.
57
58
  email:
58
59
  - naitodai@gmail.com
59
60
  - demeter.istvan@gmail.com
61
+ - drahostamas@gmail.com
60
62
  executables: []
61
63
  extensions: []
62
64
  extra_rdoc_files: []
@@ -73,6 +75,7 @@ files:
73
75
  - lib/valigator/csv.rb
74
76
  - lib/valigator/csv/error.rb
75
77
  - lib/valigator/csv/field_validators.rb
78
+ - lib/valigator/csv/field_validators/base.rb
76
79
  - lib/valigator/csv/field_validators/date.rb
77
80
  - lib/valigator/csv/field_validators/float.rb
78
81
  - lib/valigator/csv/field_validators/integer.rb