strong_csv 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -39
- data/lib/strong_csv/types/boolean.rb +1 -1
- data/lib/strong_csv/types/float.rb +2 -2
- data/lib/strong_csv/types/integer.rb +2 -2
- data/lib/strong_csv/types/literal.rb +10 -10
- data/lib/strong_csv/types/string.rb +2 -2
- data/lib/strong_csv/types/time.rb +2 -2
- data/lib/strong_csv/version.rb +1 -1
- data/lib/strong_csv.rb +0 -2
- metadata +3 -24
- data/lib/strong_csv/i18n.rb +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c242c3b580ec02d431ae78bb7b8f370ef21248dae5fb89ea7ee158b0c9c04c6
|
4
|
+
data.tar.gz: 2d880a823b44c1da78eeb6b79196c56ff46e937efe86ac17e8a522ea8b97f4a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81bcf7718f3b792f6ecc394cccc5eb610b32ecb89b9dd492d3f39ab5dadebb633b1c9f4bd804de355902632fd1790fb3bb7b5789a7bb79a6eff6ee1860078491
|
7
|
+
data.tar.gz: 39d417143c5262d1ac781bdd5414d5021e5018b5791a0d6ed6df7c0954b008154c8bc6542ce5cdc184b00b3c4c40a5bcfc4366872610a123feb3af93c991901d
|
data/README.md
CHANGED
@@ -402,45 +402,6 @@ result[1].slice(:priority, :size) # => {:priority=>30, :size=>"A"} ("A" is not o
|
|
402
402
|
result[2].slice(:priority, :size) # => {:priority=>"11", :size=>"S"} (11 is not one of 10, 20, and 30)
|
403
403
|
```
|
404
404
|
|
405
|
-
## I18n (Internationalization)
|
406
|
-
|
407
|
-
strong_csv depends on [i18n](https://rubygems.org/gems/i18n) for internationalization.
|
408
|
-
If you want to have a locale-specific error message, put the message catalog in your locale files.
|
409
|
-
Here is an example of a locale file.
|
410
|
-
|
411
|
-
```yaml
|
412
|
-
ja:
|
413
|
-
strong_csv:
|
414
|
-
boolean:
|
415
|
-
cant_be_casted: "`%{value}`はBooleanに変換できません"
|
416
|
-
float:
|
417
|
-
cant_be_casted: "`%{value}`はFloatに変換できません"
|
418
|
-
constraint_error: "`%{value}`は指定された成約を満たしていません",
|
419
|
-
integer:
|
420
|
-
cant_be_casted: "`%{value}`はIntegerに変換できません"
|
421
|
-
constraint_error: "`%{value}`は指定された成約を満たしていません",
|
422
|
-
literal:
|
423
|
-
integer:
|
424
|
-
unexpected: "`%{expected}`ではなく`%{value}`が入力されています"
|
425
|
-
cant_be_casted: "`%{expected}`ではなく`%{value}`が入力されています"
|
426
|
-
float:
|
427
|
-
unexpected: "`%{expected}`ではなく`%{value}`が入力されています"
|
428
|
-
cant_be_casted: "`%{value}`はFloatに変換できません"
|
429
|
-
string:
|
430
|
-
unexpected: "`%{expected}`ではなく`%{value}`が入力されています"
|
431
|
-
range:
|
432
|
-
cant_be_casted: "`%{value}`は`%{expected}`の始端に変換できません"
|
433
|
-
out_of_range: "`%{value}`は`%{range}`の範囲外です"
|
434
|
-
regexp:
|
435
|
-
cant_be_casted: "`%{value}`はStringに変換できません"
|
436
|
-
unexpected: "`%{value}`は`%{expected}`とマッチしませんでした"
|
437
|
-
string:
|
438
|
-
cant_be_casted: "`%{value}`はStringに変換できません"
|
439
|
-
out_of_range: "`%{value}`の文字数は`%{range}`の範囲外です"
|
440
|
-
time:
|
441
|
-
cant_be_casted: "`%{value}`は`%{time_format}`でTimeに変換できません"
|
442
|
-
```
|
443
|
-
|
444
405
|
## Contributing
|
445
406
|
|
446
407
|
Bug reports and pull requests are welcome on the [GitHub repository](https://github.com/yykamei/strong_csv).
|
@@ -17,7 +17,7 @@ class StrongCSV
|
|
17
17
|
boolean = FALSE_VALUES.include?(value) ? false : nil
|
18
18
|
return ValueResult.new(value: boolean, original_value: value) unless boolean.nil?
|
19
19
|
|
20
|
-
ValueResult.new(original_value: value, error_messages: [
|
20
|
+
ValueResult.new(original_value: value, error_messages: ["`#{value.inspect}` can't be casted to Boolean"])
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
@@ -21,10 +21,10 @@ class StrongCSV
|
|
21
21
|
if @constraint.call(float)
|
22
22
|
ValueResult.new(value: float, original_value: value)
|
23
23
|
else
|
24
|
-
ValueResult.new(original_value: value, error_messages: [
|
24
|
+
ValueResult.new(original_value: value, error_messages: ["`#{value.inspect}` does not satisfy the specified constraint"])
|
25
25
|
end
|
26
26
|
rescue ArgumentError, TypeError
|
27
|
-
ValueResult.new(original_value: value, error_messages: [
|
27
|
+
ValueResult.new(original_value: value, error_messages: ["`#{value.inspect}` can't be casted to Float"])
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -21,10 +21,10 @@ class StrongCSV
|
|
21
21
|
if @constraint.call(int)
|
22
22
|
ValueResult.new(value: int, original_value: value)
|
23
23
|
else
|
24
|
-
ValueResult.new(original_value: value, error_messages: [
|
24
|
+
ValueResult.new(original_value: value, error_messages: ["`#{value.inspect}` does not satisfy the specified constraint"])
|
25
25
|
end
|
26
26
|
rescue ArgumentError, TypeError
|
27
|
-
ValueResult.new(original_value: value, error_messages: [
|
27
|
+
ValueResult.new(original_value: value, error_messages: ["`#{value.inspect}` can't be casted to Integer"])
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -13,10 +13,10 @@ class StrongCSV
|
|
13
13
|
if int == self
|
14
14
|
ValueResult.new(value: int, original_value: value)
|
15
15
|
else
|
16
|
-
ValueResult.new(original_value: value, error_messages: [
|
16
|
+
ValueResult.new(original_value: value, error_messages: ["`#{inspect}` is expected, but `#{int.inspect}` was given"])
|
17
17
|
end
|
18
18
|
rescue ArgumentError, TypeError
|
19
|
-
ValueResult.new(original_value: value, error_messages: [
|
19
|
+
ValueResult.new(original_value: value, error_messages: ["`#{value.inspect}` can't be casted to Integer"])
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -28,10 +28,10 @@ class StrongCSV
|
|
28
28
|
if float == self
|
29
29
|
ValueResult.new(value: float, original_value: value)
|
30
30
|
else
|
31
|
-
ValueResult.new(original_value: value, error_messages: [
|
31
|
+
ValueResult.new(original_value: value, error_messages: ["`#{inspect}` is expected, but `#{float.inspect}` was given"])
|
32
32
|
end
|
33
33
|
rescue ArgumentError, TypeError
|
34
|
-
ValueResult.new(original_value: value, error_messages: [
|
34
|
+
ValueResult.new(original_value: value, error_messages: ["`#{value.inspect}` can't be casted to Float"])
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -39,7 +39,7 @@ class StrongCSV
|
|
39
39
|
# @param value [Object] Value to be casted to Range
|
40
40
|
# @return [ValueResult]
|
41
41
|
def cast(value)
|
42
|
-
return ValueResult.new(original_value: value, error_messages: [
|
42
|
+
return ValueResult.new(original_value: value, error_messages: ["`#{value.inspect}` can't be casted to the beginning of `#{inspect}`"]) if value.nil?
|
43
43
|
|
44
44
|
casted = case self.begin
|
45
45
|
when ::Float
|
@@ -54,10 +54,10 @@ class StrongCSV
|
|
54
54
|
if cover?(casted)
|
55
55
|
ValueResult.new(value: casted, original_value: value)
|
56
56
|
else
|
57
|
-
ValueResult.new(original_value: value, error_messages: [
|
57
|
+
ValueResult.new(original_value: value, error_messages: ["`#{casted.inspect}` is not within `#{inspect}`"])
|
58
58
|
end
|
59
59
|
rescue ArgumentError
|
60
|
-
ValueResult.new(original_value: value, error_messages: [
|
60
|
+
ValueResult.new(original_value: value, error_messages: ["`#{value.inspect}` can't be casted to the beginning of `#{inspect}`"])
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -68,7 +68,7 @@ class StrongCSV
|
|
68
68
|
if self == value
|
69
69
|
ValueResult.new(value: self, original_value: value)
|
70
70
|
else
|
71
|
-
ValueResult.new(original_value: value, error_messages: [
|
71
|
+
ValueResult.new(original_value: value, error_messages: ["`#{inspect}` is expected, but `#{value.inspect}` was given"])
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
@@ -77,12 +77,12 @@ class StrongCSV
|
|
77
77
|
# @param value [Object] Value to be casted to String
|
78
78
|
# @return [ValueResult]
|
79
79
|
def cast(value)
|
80
|
-
return ValueResult.new(original_value: value, error_messages: [
|
80
|
+
return ValueResult.new(original_value: value, error_messages: ["`#{value.inspect}` can't be casted to String"]) if value.nil?
|
81
81
|
|
82
82
|
if self =~ value
|
83
83
|
ValueResult.new(value: value, original_value: value)
|
84
84
|
else
|
85
|
-
ValueResult.new(original_value: value, error_messages: [
|
85
|
+
ValueResult.new(original_value: value, error_messages: ["`#{value.inspect}` did not match `#{inspect}`"])
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
@@ -15,11 +15,11 @@ class StrongCSV
|
|
15
15
|
# @param value [Object] Value to be casted to Boolean
|
16
16
|
# @return [ValueResult]
|
17
17
|
def cast(value)
|
18
|
-
return ValueResult.new(original_value: value, error_messages: [
|
18
|
+
return ValueResult.new(original_value: value, error_messages: ["`#{value.inspect}` can't be casted to String"]) if value.nil?
|
19
19
|
|
20
20
|
casted = String(value)
|
21
21
|
if @within && !@within.cover?(casted.size)
|
22
|
-
ValueResult.new(original_value: value, error_messages: [
|
22
|
+
ValueResult.new(original_value: value, error_messages: ["The length of `#{value.inspect}` is out of range `#{@within.inspect}`"])
|
23
23
|
else
|
24
24
|
ValueResult.new(value: casted, original_value: value)
|
25
25
|
end
|
@@ -15,11 +15,11 @@ class StrongCSV
|
|
15
15
|
# @param value [Object] Value to be casted to Time
|
16
16
|
# @return [ValueResult]
|
17
17
|
def cast(value)
|
18
|
-
return ValueResult.new(original_value: value, error_messages: [
|
18
|
+
return ValueResult.new(original_value: value, error_messages: ["`#{value.inspect}` can't be casted to Time with the format `#{@format.inspect}`"]) if value.nil?
|
19
19
|
|
20
20
|
ValueResult.new(value: ::Time.strptime(value.to_s, @format), original_value: value)
|
21
21
|
rescue ArgumentError
|
22
|
-
ValueResult.new(original_value: value, error_messages: [
|
22
|
+
ValueResult.new(original_value: value, error_messages: ["`#{value.inspect}` can't be casted to Time with the format `#{@format.inspect}`"])
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
data/lib/strong_csv/version.rb
CHANGED
data/lib/strong_csv.rb
CHANGED
@@ -4,10 +4,8 @@ require "csv"
|
|
4
4
|
require "forwardable"
|
5
5
|
require "set"
|
6
6
|
require "time"
|
7
|
-
require "i18n"
|
8
7
|
|
9
8
|
require_relative "strong_csv/version"
|
10
|
-
require_relative "strong_csv/i18n"
|
11
9
|
require_relative "strong_csv/value_result"
|
12
10
|
require_relative "strong_csv/types/base"
|
13
11
|
require_relative "strong_csv/types/boolean"
|
metadata
CHANGED
@@ -1,35 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strong_csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yutaka Kamei
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-07-
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: i18n
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 1.8.11
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '2'
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 1.8.11
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '2'
|
11
|
+
date: 2022-07-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
33
13
|
description: strong_csv is a type checker for a CSV file. It lets developers declare
|
34
14
|
types for each column to ensure all cells are satisfied with desired types.
|
35
15
|
email:
|
@@ -41,7 +21,6 @@ files:
|
|
41
21
|
- LICENSE
|
42
22
|
- README.md
|
43
23
|
- lib/strong_csv.rb
|
44
|
-
- lib/strong_csv/i18n.rb
|
45
24
|
- lib/strong_csv/let.rb
|
46
25
|
- lib/strong_csv/row.rb
|
47
26
|
- lib/strong_csv/types/base.rb
|
data/lib/strong_csv/i18n.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
I18n.backend.store_translations(
|
4
|
-
:en, {
|
5
|
-
_strong_csv: {
|
6
|
-
boolean: {
|
7
|
-
cant_be_casted: "`%{value}` can't be casted to Boolean",
|
8
|
-
},
|
9
|
-
float: {
|
10
|
-
cant_be_casted: "`%{value}` can't be casted to Float",
|
11
|
-
constraint_error: "`%{value}` does not satisfy the specified constraint",
|
12
|
-
},
|
13
|
-
integer: {
|
14
|
-
cant_be_casted: "`%{value}` can't be casted to Integer",
|
15
|
-
constraint_error: "`%{value}` does not satisfy the specified constraint",
|
16
|
-
},
|
17
|
-
literal: {
|
18
|
-
integer: {
|
19
|
-
unexpected: "`%{expected}` is expected, but `%{value}` was given",
|
20
|
-
cant_be_casted: "`%{value}` can't be casted to Integer",
|
21
|
-
},
|
22
|
-
float: {
|
23
|
-
unexpected: "`%{expected}` is expected, but `%{value}` was given",
|
24
|
-
cant_be_casted: "`%{value}` can't be casted to Float",
|
25
|
-
},
|
26
|
-
string: {
|
27
|
-
unexpected: "`%{expected}` is expected, but `%{value}` was given",
|
28
|
-
},
|
29
|
-
range: {
|
30
|
-
cant_be_casted: "`%{value}` can't be casted to the beginning of `%{expected}`",
|
31
|
-
out_of_range: "`%{value}` is not within `%{range}`",
|
32
|
-
},
|
33
|
-
regexp: {
|
34
|
-
cant_be_casted: "`%{value}` can't be casted to String",
|
35
|
-
unexpected: "`%{value}` did not match `%{expected}`",
|
36
|
-
},
|
37
|
-
},
|
38
|
-
string: {
|
39
|
-
cant_be_casted: "`%{value}` can't be casted to String",
|
40
|
-
out_of_range: "The length of `%{value}` is out of range `%{range}`",
|
41
|
-
},
|
42
|
-
time: {
|
43
|
-
cant_be_casted: "`%{value}` can't be casted to Time with the format `%{time_format}`",
|
44
|
-
},
|
45
|
-
},
|
46
|
-
},
|
47
|
-
)
|