eco-helpers 2.7.1 → 2.7.2
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80de08cdef4ada108f4853214720d30985461e43309b9d442932975e7400bf20
|
4
|
+
data.tar.gz: c9174f97cd87f2c092f3ec892397fa53711a7efd61d8bbd456b3e68d62d8cf03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfc1092476a865d1902eaf1d241b27f4a141b72d287524f41107d13b9e447a1a83d04f278e1a04046e1435b7ce5b919e597a030c7c4eb8ccadb9431e90ace039
|
7
|
+
data.tar.gz: 4bf36063e2b8eca6051343a9b18ecbe61ac3e04c1789be8dc269d59f36c444690475ff0fdf42113ca74e035a41bef0d12e6d574a9845966ebbb73d4b303ef47d
|
data/CHANGELOG.md
CHANGED
@@ -16,30 +16,22 @@ class Eco::API::Common::People::DefaultParsers::DateParser < Eco::API::Common::L
|
|
16
16
|
|
17
17
|
def parse_date(value, attr:)
|
18
18
|
return value.map {|val| parse_date(val, attr: attr)}.compact if value.is_a?(Enumerable)
|
19
|
+
return nil if blank?(value)
|
19
20
|
|
20
|
-
return nil if value.nil?
|
21
21
|
value = value.to_s.strip
|
22
|
-
return
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
nil
|
29
|
-
end
|
30
|
-
else
|
31
|
-
wrong!(value, attr: attr)
|
32
|
-
nil
|
33
|
-
end
|
22
|
+
return wrong!(value, attr: attr) unless date?(value)
|
23
|
+
|
24
|
+
date = Date.parse(value)
|
25
|
+
return date if valid_range?(date)
|
26
|
+
|
27
|
+
wrong!(value, attr: attr, desc: 'Date out of range (1900-2099). Given: ')
|
34
28
|
rescue TypeError, Date::Error
|
35
29
|
nil
|
36
30
|
end
|
37
31
|
|
38
32
|
def serialize_date(value)
|
39
33
|
return value.map {|val| serialize_date(val)}.compact if value.is_a?(Enumerable)
|
40
|
-
|
41
|
-
return nil if value.nil?
|
42
|
-
return nil if value.to_s.strip.empty?
|
34
|
+
return nil if blank?(value)
|
43
35
|
return value if value.is_a?(String)
|
44
36
|
return nil unless [Date, Time].any? {|type| value.is_a?(type)}
|
45
37
|
value&.strftime('%Y-%m-%d')
|
@@ -47,18 +39,6 @@ class Eco::API::Common::People::DefaultParsers::DateParser < Eco::API::Common::L
|
|
47
39
|
nil
|
48
40
|
end
|
49
41
|
|
50
|
-
def wrong!(value, attr:, desc: "Can't make a date out of")
|
51
|
-
return if wrong(attr).key?(value)
|
52
|
-
wrong(attr)[value] = value
|
53
|
-
log(:warn) { "#{desc} '#{value}' for '#{attr}'" }
|
54
|
-
end
|
55
|
-
|
56
|
-
def wrong(attr = nil)
|
57
|
-
@wrong ||= {}
|
58
|
-
return @wrong if attr.nil?
|
59
|
-
@wrong[attr] ||= {}
|
60
|
-
end
|
61
|
-
|
62
42
|
def date?(value)
|
63
43
|
return true if value.nil?
|
64
44
|
return true if value.to_s.strip.empty?
|
@@ -74,6 +54,19 @@ class Eco::API::Common::People::DefaultParsers::DateParser < Eco::API::Common::L
|
|
74
54
|
max_date >= date
|
75
55
|
end
|
76
56
|
|
57
|
+
def wrong!(value, attr:, desc: "Can't make a date out of")
|
58
|
+
return if wrong(attr).key?(value)
|
59
|
+
wrong(attr)[value] = value
|
60
|
+
log(:warn) { "#{desc} '#{value}' for '#{attr}'" }
|
61
|
+
nil
|
62
|
+
end
|
63
|
+
|
64
|
+
def wrong(attr = nil)
|
65
|
+
@wrong ||= {}
|
66
|
+
return @wrong if attr.nil?
|
67
|
+
@wrong[attr] ||= {}
|
68
|
+
end
|
69
|
+
|
77
70
|
def min_date
|
78
71
|
@min_date ||= Date.parse(MIN_DATE)
|
79
72
|
end
|
@@ -81,4 +74,10 @@ class Eco::API::Common::People::DefaultParsers::DateParser < Eco::API::Common::L
|
|
81
74
|
def max_date
|
82
75
|
@max_date ||= Date.parse(MAX_DATE)
|
83
76
|
end
|
77
|
+
|
78
|
+
def blank?(value)
|
79
|
+
return true if value.nil?
|
80
|
+
return true if value.to_s.strip.empty?
|
81
|
+
false
|
82
|
+
end
|
84
83
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class Eco::API::Common::People::DefaultParsers::NumericParser < Eco::API::Common::Loaders::Parser
|
2
2
|
attribute :number
|
3
3
|
|
4
|
-
def parser(value,
|
5
|
-
parse_number(value)
|
4
|
+
def parser(value, deps)
|
5
|
+
parse_number(value, attr: deps['attr'])
|
6
6
|
end
|
7
7
|
|
8
8
|
def serializer(value, _deps)
|
@@ -11,13 +11,13 @@ class Eco::API::Common::People::DefaultParsers::NumericParser < Eco::API::Common
|
|
11
11
|
|
12
12
|
private
|
13
13
|
|
14
|
-
def parse_number(value)
|
15
|
-
return value.map {|val| parse_number(val)}.compact if value.is_a?(Enumerable)
|
14
|
+
def parse_number(value, attr:)
|
15
|
+
return value.map {|val| parse_number(val, attr: attr)}.compact if value.is_a?(Enumerable)
|
16
|
+
return nil if blank?(value)
|
16
17
|
|
17
|
-
return nil if value.nil?
|
18
18
|
value = value.to_s.strip
|
19
|
-
return
|
20
|
-
|
19
|
+
return wrong!(value, attr: attr) unless number?(value)
|
20
|
+
|
21
21
|
value.to_f
|
22
22
|
rescue ArgumentError, TypeError
|
23
23
|
nil
|
@@ -28,4 +28,23 @@ class Eco::API::Common::People::DefaultParsers::NumericParser < Eco::API::Common
|
|
28
28
|
rescue ArgumentError, TypeError
|
29
29
|
false
|
30
30
|
end
|
31
|
+
|
32
|
+
def wrong!(value, attr:, desc: "Can't make a number out of")
|
33
|
+
return if wrong(attr).key?(value)
|
34
|
+
wrong(attr)[value] = value
|
35
|
+
log(:warn) { "#{desc} '#{value}' for '#{attr}'" }
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
|
39
|
+
def wrong(attr = nil)
|
40
|
+
@wrong ||= {}
|
41
|
+
return @wrong if attr.nil?
|
42
|
+
@wrong[attr] ||= {}
|
43
|
+
end
|
44
|
+
|
45
|
+
def blank?(value)
|
46
|
+
return true if value.nil?
|
47
|
+
return true if value.to_s.strip.empty?
|
48
|
+
false
|
49
|
+
end
|
31
50
|
end
|
data/lib/eco/version.rb
CHANGED