schema-model 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/schema.rb +1 -0
- data/lib/schema/associations/dynamic_types.rb +4 -0
- data/lib/schema/parsers/american.rb +55 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c800b07a0df6dbd84e521624bd2904115f40db9502cddb565aeebaa03e481a6
|
4
|
+
data.tar.gz: cb99655704a840ab6c20869f44500782760d6e9c6d731b26d2df03ca9c375ebe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d462e67214f46b03f65bce3e2a9d5e6315ef8bd1da3988de59df55bb1d770ee26fa6178c6b72d77cdca37f95f86a0fa14cd2b53c054c7aa936e1ee4ba6585a1a
|
7
|
+
data.tar.gz: b6f643ab0b9934b22047821223e3d8f5f8f5f216be3687622f3d3272ef4e65f5d54c51d6bf5559f5f79231b8c1c91b371f06e1bba96ad63182410b8eeb6e2346
|
data/lib/schema.rb
CHANGED
@@ -16,6 +16,7 @@ module Schema
|
|
16
16
|
|
17
17
|
# Schema::Parsers are used to convert values into the correct data type
|
18
18
|
module Parsers
|
19
|
+
autoload :American, 'schema/parsers/american'
|
19
20
|
autoload :Array, 'schema/parsers/array'
|
20
21
|
autoload :Common, 'schema/parsers/common'
|
21
22
|
autoload :Hash, 'schema/parsers/hash'
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
module Schema
|
6
|
+
module Parsers
|
7
|
+
# Schema::Parsers::American parses dates and times in American format
|
8
|
+
module American
|
9
|
+
DATE_FORMAT = '%m/%d/%Y'
|
10
|
+
TIME_FORMAT = '%m/%d/%Y %H:%M:%S'
|
11
|
+
|
12
|
+
def parse_american_date(field_name, parsing_errors, value)
|
13
|
+
case value
|
14
|
+
when Date
|
15
|
+
value
|
16
|
+
when Time
|
17
|
+
value.to_date
|
18
|
+
when String
|
19
|
+
begin
|
20
|
+
Date.strptime(value, DATE_FORMAT)
|
21
|
+
rescue ArgumentError
|
22
|
+
parsing_errors.add(field_name, ::Schema::ParsingErrors::INVALID)
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
when nil
|
26
|
+
nil
|
27
|
+
else
|
28
|
+
parsing_errors.add(field_name, ::Schema::ParsingErrors::UNHANDLED_TYPE)
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def parse_american_time(field_name, parsing_errors, value)
|
34
|
+
case value
|
35
|
+
when Time
|
36
|
+
value
|
37
|
+
when Date
|
38
|
+
value.to_time
|
39
|
+
when String
|
40
|
+
begin
|
41
|
+
Time.strptime(value, TIME_FORMAT)
|
42
|
+
rescue ArgumentError
|
43
|
+
parsing_errors.add(field_name, ::Schema::ParsingErrors::INVALID)
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
when nil
|
47
|
+
nil
|
48
|
+
else
|
49
|
+
parsing_errors.add(field_name, ::Schema::ParsingErrors::UNHANDLED_TYPE)
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Doug Youch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inheritance-helper
|
@@ -42,6 +42,7 @@ files:
|
|
42
42
|
- lib/schema/csv_parser.rb
|
43
43
|
- lib/schema/errors.rb
|
44
44
|
- lib/schema/model.rb
|
45
|
+
- lib/schema/parsers/american.rb
|
45
46
|
- lib/schema/parsers/array.rb
|
46
47
|
- lib/schema/parsers/common.rb
|
47
48
|
- lib/schema/parsers/hash.rb
|