csv_row_model 0.4.0 → 0.4.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: d13ce436eddba3a6cd5ad084cbd534098637279b
4
- data.tar.gz: c0132db76eb2855b4fc0eddbe288a54e741e0544
3
+ metadata.gz: 44a0bf8c6a12a2a9a8c3cb74cf3563928313ac96
4
+ data.tar.gz: a75edbc43ee598166facf68baf98555355e15660
5
5
  SHA512:
6
- metadata.gz: 92c5b48c05ca65a73f997061a0db142b9cb684940b6adca4dee691d33b00b0bb115d4db05d6375da7e7b870c5334c667f95f4b7d5525d6c74c4eee44042d08a1
7
- data.tar.gz: 4885e9fc4282bc8974ed6fe3f7db11c4f39875b142a0e0daca002341aff015c5f68d25017727072369592f6b6a7f50ad460c6d86cbdb7839dedad8bcf0442366
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 => ->(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
- Date => ->(s) { s.present? ? Date.parse(s) : s }
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)`
@@ -0,0 +1,9 @@
1
+ class DateTimeFormatValidator < ActiveModel::EachValidator # :nodoc:
2
+ def validate_each(record, attribute, value)
3
+ begin
4
+ DateTime.parse(value.to_s)
5
+ rescue ArgumentError
6
+ record.errors.add(attribute, 'is not a Date Time format')
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module CsvRowModel
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
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.0
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