Class: Haecksler::Column
- Inherits:
-
Object
- Object
- Haecksler::Column
- Defined in:
- lib/haecksler/column.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{type: :string, date_format: nil}
Instance Attribute Summary collapse
-
#date_format ⇒ Object
readonly
Returns the value of attribute date_format.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(options = {type: :string}) ⇒ Column
constructor
A new instance of Column.
- #parse(string_value) ⇒ Object
Constructor Details
#initialize(options = {type: :string}) ⇒ Column
Returns a new instance of Column.
33 34 35 36 37 38 39 |
# File 'lib/haecksler/column.rb', line 33 def initialize( = {type: :string}) = DEFAULT_OPTIONS.merge() @name = [:name] @size = [:size] @type = [:type] @date_format = [:date_format] end |
Instance Attribute Details
#date_format ⇒ Object (readonly)
Returns the value of attribute date_format.
29 30 31 |
# File 'lib/haecksler/column.rb', line 29 def date_format @date_format end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
29 30 31 |
# File 'lib/haecksler/column.rb', line 29 def name @name end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
29 30 31 |
# File 'lib/haecksler/column.rb', line 29 def size @size end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
29 30 31 |
# File 'lib/haecksler/column.rb', line 29 def type @type end |
Instance Method Details
#parse(string_value) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/haecksler/column.rb', line 41 def parse(string_value) parsed = ParsedColumn.new(self) parsed.value = begin case type when :nil nil when :string String(string_value).rstrip when :integer Integer(string_value) when :float Float(string_value) when :date if date_format.nil? Date.parse(string_value) else Date.strptime(string_value, date_format) end when :datetime if date_format.nil? DateTime.parse(string_value) else DateTime.strptime(string_value, date_format) end else nil end rescue TypeError.new(string_value, self) end parsed end |