Class: Sheetah::Attribute
- Inherits:
-
Object
- Object
- Sheetah::Attribute
- Defined in:
- lib/sheetah/attribute.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #each_column(config) ⇒ Object
-
#initialize(key:, type:) ⇒ Attribute
constructor
A new instance of Attribute.
Constructor Details
#initialize(key:, type:) ⇒ Attribute
Returns a new instance of Attribute.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sheetah/attribute.rb', line 7 def initialize(key:, type:) @key = key @type = case type when Hash CompositeType.new(**type) when Array CompositeType.new(composite: :array, scalars: type) else ScalarType.new(type) end freeze end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
23 24 25 |
# File 'lib/sheetah/attribute.rb', line 23 def key @key end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
23 24 25 |
# File 'lib/sheetah/attribute.rb', line 23 def type @type end |
Instance Method Details
#each_column(config) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sheetah/attribute.rb', line 25 def each_column(config) return enum_for(:each_column, config) unless block_given? compiled_type = type.compile(config.types) type.each_column do |index, required| header, header_pattern = config.header(key, index) yield Column.new( key: key, type: compiled_type, index: index, header: header, header_pattern: header_pattern, required: required ) end end |