Class: CSVImportable::TypeParser
- Inherits:
-
Object
- Object
- CSVImportable::TypeParser
- Defined in:
- lib/csv_importable/type_parser.rb
Direct Known Subclasses
BooleanTypeParser, DateTypeParser, FloatTypeParser, IntegerTypeParser, PercentTypeParser, SelectTypeParser, StringTypeParser
Defined Under Namespace
Classes: BooleanTypeParser, DateTypeParser, FloatTypeParser, IntegerTypeParser, PercentTypeParser, SelectTypeParser, StringTypeParser
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#row ⇒ Object
readonly
Returns the value of attribute row.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(key, args = {}) ⇒ TypeParser
constructor
A new instance of TypeParser.
- #parse ⇒ Object
Constructor Details
#initialize(key, args = {}) ⇒ TypeParser
Returns a new instance of TypeParser.
5 6 7 8 9 10 11 |
# File 'lib/csv_importable/type_parser.rb', line 5 def initialize(key, args = {}) @key = key @row = args[:row] @required = args.fetch(:required, false) @value = args.fetch(:value, pull_value_from_row) after_init(args) end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
3 4 5 |
# File 'lib/csv_importable/type_parser.rb', line 3 def key @key end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
3 4 5 |
# File 'lib/csv_importable/type_parser.rb', line 3 def required @required end |
#row ⇒ Object (readonly)
Returns the value of attribute row.
3 4 5 |
# File 'lib/csv_importable/type_parser.rb', line 3 def row @row end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
3 4 5 |
# File 'lib/csv_importable/type_parser.rb', line 3 def value @value end |
Instance Method Details
#parse ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/csv_importable/type_parser.rb', line 13 def parse if value.blank? check_required return nil end parsed_val = nil begin parsed_val = parse_val rescue raise_parsing_error end raise_parsing_error if parsed_val.nil? parsed_val end |