Class: RecordLoader::Attribute
- Inherits:
-
Object
- Object
- RecordLoader::Attribute
- Defined in:
- lib/record_loader/attribute.rb
Overview
Used by the generator to help guide the generation of the initial yaml files
Constant Summary collapse
- BASE_TIME =
Time.parse('2021-10-08 13:00:40 +0100')
- BASE_DATE =
Date.parse('2021-10-08')
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
The default of the attribute.
-
#name ⇒ String
readonly
The name of the attribute, takes the column name.
-
#type ⇒ Symbol
readonly
The attribute type (eg. :string) as returned by the rails connection adapter.
Instance Method Summary collapse
-
#initialize(name, type, default) ⇒ Attribute
constructor
Create a new attribute.
- #ruby_value(index) ⇒ Object
- #value(index) ⇒ Object
Constructor Details
#initialize(name, type, default) ⇒ Attribute
Create a new attribute
28 29 30 31 32 |
# File 'lib/record_loader/attribute.rb', line 28 def initialize(name, type, default) @name = name @type = type @default = default end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns The default of the attribute.
19 20 21 |
# File 'lib/record_loader/attribute.rb', line 19 def default @default end |
#name ⇒ String (readonly)
Returns The name of the attribute, takes the column name.
13 14 15 |
# File 'lib/record_loader/attribute.rb', line 13 def name @name end |
#type ⇒ Symbol (readonly)
Returns The attribute type (eg. :string) as returned by the rails connection adapter.
16 17 18 |
# File 'lib/record_loader/attribute.rb', line 16 def type @type end |
Instance Method Details
#ruby_value(index) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/record_loader/attribute.rb', line 42 def ruby_value(index) case type when :datetime, :timestamp then "Time.parse('#{value(index)}')" when :date then "Date.parse('#{value(index)}')" else value(index).inspect end end |
#value(index) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/record_loader/attribute.rb', line 34 def value(index) if @default.nil? value_for_type(index) else @default end end |