Class: Sheetah::Attribute
- Inherits:
-
Object
- Object
- Sheetah::Attribute
- Defined in:
- lib/sheetah/attribute.rb
Overview
The main building block of a Template.
Instance Attribute Summary collapse
- #key ⇒ Symbol, String readonly
-
#type ⇒ AttributeType
readonly
An abstract specification of the type of a value in the resulting hash.
Class Method Summary collapse
-
.build(key:, type:) ⇒ Attribute
A smarter version of #initialize.
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.
25 26 27 28 |
# File 'lib/sheetah/attribute.rb', line 25 def initialize(key:, type:) @key = key @type = type end |
Instance Attribute Details
#key ⇒ Symbol, String (readonly)
31 32 33 |
# File 'lib/sheetah/attribute.rb', line 31 def key @key end |
#type ⇒ AttributeType (readonly)
An abstract specification of the type of a value in the resulting hash.
It will be used to produce the concrete type of a column (or a list of columns) when a TemplateConfig is applied to the Template owning the attribtue.
39 40 41 |
# File 'lib/sheetah/attribute.rb', line 39 def type @type end |
Class Method Details
.build(key:, type:) ⇒ Attribute
A smarter version of #initialize.
-
It automatically freezes the instance before returning it.
-
It instantiates and injects a type automatically by passing the arguments to Sheetah::AttributeTypes.build.
16 17 18 19 20 21 |
# File 'lib/sheetah/attribute.rb', line 16 def self.build(key:, type:) type = AttributeTypes.build(type) attribute = new(key: key, type: type) attribute.freeze end |
Instance Method Details
#each_column(config) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sheetah/attribute.rb', line 41 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 |