csv_row_model 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/csv_row_model.rb +1 -0
- data/lib/csv_row_model/import/attributes.rb +8 -7
- data/lib/csv_row_model/validators/date_time_format.rb +9 -0
- data/lib/csv_row_model/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44a0bf8c6a12a2a9a8c3cb74cf3563928313ac96
|
4
|
+
data.tar.gz: a75edbc43ee598166facf68baf98555355e15660
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fa219f5da727166844f7d75519670fe0df6d98926caf0d72abafa8a84961af0513a87b69be00219671d5af2161edec57740e0128160d26952e7ef72db9cf69d
|
7
|
+
data.tar.gz: 26a27334de6c098629a3d446eda5aece191bcd9080d732476e65e1534e79b7fb3e8501c22ae5f72ec3cfceef62e9600610b5fabec8a6405c4e43bb190fed7c17
|
data/README.md
CHANGED
@@ -173,7 +173,7 @@ class ProjectImportRowModel
|
|
173
173
|
end
|
174
174
|
```
|
175
175
|
|
176
|
-
There are validators for different types: `Boolean`, `Date`, `Float`, `Integer`. See [Validations](#validations) for more.
|
176
|
+
There are validators for different types: `Boolean`, `Date`, `DateTime`, `Float`, `Integer`. See [Validations](#validations) for more.
|
177
177
|
|
178
178
|
#### Default
|
179
179
|
Sets the default value of the cell:
|
@@ -344,7 +344,7 @@ Included is [`ActiveWarnings`](https://github.com/s12chung/active_warnings) on `
|
|
344
344
|
|
345
345
|
|
346
346
|
### Type Format
|
347
|
-
Notice that there are validators given for different types: `Boolean`, `Date`, `Float`, `Integer`:
|
347
|
+
Notice that there are validators given for different types: `Boolean`, `Date`, `DateTime`, `Float`, `Integer`:
|
348
348
|
|
349
349
|
```ruby
|
350
350
|
class ProjectImportRowModel
|
data/lib/csv_row_model.rb
CHANGED
@@ -36,6 +36,7 @@ require 'csv_row_model/validators/default_change'
|
|
36
36
|
|
37
37
|
require 'csv_row_model/validators/number_validator'
|
38
38
|
require 'csv_row_model/validators/boolean_format'
|
39
|
+
require 'csv_row_model/validators/date_time_format'
|
39
40
|
require 'csv_row_model/validators/date_format'
|
40
41
|
require 'csv_row_model/validators/float_format'
|
41
42
|
require 'csv_row_model/validators/integer_format'
|
@@ -10,17 +10,18 @@ module CsvRowModel
|
|
10
10
|
end
|
11
11
|
|
12
12
|
# Classes with a validations associated with them in csv_row_model/validators
|
13
|
-
PARSE_VALIDATION_CLASSES = [Boolean, Integer, Float, Date].freeze
|
13
|
+
PARSE_VALIDATION_CLASSES = [Boolean, Integer, Float, Date, DateTime].freeze
|
14
14
|
|
15
15
|
# Mapping of column type classes to a parsing lambda. These are applied after {Import.format_cell}.
|
16
16
|
# Can pass custom Proc with :parse option.
|
17
17
|
CLASS_TO_PARSE_LAMBDA = {
|
18
|
-
nil
|
19
|
-
Boolean
|
20
|
-
String
|
21
|
-
Integer
|
22
|
-
Float
|
23
|
-
|
18
|
+
nil => ->(s) { s },
|
19
|
+
Boolean => ->(s) { s =~ BooleanFormatValidator::FALSE_BOOLEAN_REGEX ? false : true },
|
20
|
+
String => ->(s) { s },
|
21
|
+
Integer => ->(s) { s.to_i },
|
22
|
+
Float => ->(s) { s.to_f },
|
23
|
+
DateTime => ->(s) { s.present? ? DateTime.parse(s) : s },
|
24
|
+
Date => ->(s) { s.present? ? Date.parse(s) : s }
|
24
25
|
}.freeze
|
25
26
|
|
26
27
|
# @return [Hash] a map of `column_name => original_attribute(column_name)`
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv_row_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Chung
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- lib/csv_row_model/model/file_model.rb
|
91
91
|
- lib/csv_row_model/validators/boolean_format.rb
|
92
92
|
- lib/csv_row_model/validators/date_format.rb
|
93
|
+
- lib/csv_row_model/validators/date_time_format.rb
|
93
94
|
- lib/csv_row_model/validators/default_change.rb
|
94
95
|
- lib/csv_row_model/validators/float_format.rb
|
95
96
|
- lib/csv_row_model/validators/integer_format.rb
|