Class: Sheetah::AttributeTypes::Scalar
- Inherits:
-
Object
- Object
- Sheetah::AttributeTypes::Scalar
- Includes:
- Sheetah::AttributeType
- Defined in:
- lib/sheetah/attribute_types/scalar.rb
Overview
Class Method Summary collapse
-
.build ⇒ Scalar
A smarter version of #initialize.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #compile(container) ⇒ Object
- #each_column {|nil, value.required| ... } ⇒ Object
-
#initialize(value) ⇒ Scalar
constructor
A new instance of Scalar.
Constructor Details
#initialize(value) ⇒ Scalar
Returns a new instance of Scalar.
30 31 32 |
# File 'lib/sheetah/attribute_types/scalar.rb', line 30 def initialize(value) @value = value end |
Class Method Details
.build ⇒ Scalar
A smarter version of #initialize.
-
It automatically freezes the instance before returning it.
-
It instantiates and injects a value automatically by passing the arguments to Value.build.
The method signature is identical to the one of Value.build.
21 22 23 24 25 26 |
# File 'lib/sheetah/attribute_types/scalar.rb', line 21 def self.build(...) value = Value.build(...) scalar = new(value) scalar.freeze end |
Instance Method Details
#==(other) ⇒ Object
48 49 50 51 |
# File 'lib/sheetah/attribute_types/scalar.rb', line 48 def ==(other) other.is_a?(self.class) && value == other.value end |
#compile(container) ⇒ Object
35 36 37 |
# File 'lib/sheetah/attribute_types/scalar.rb', line 35 def compile(container) container.scalar(value.type) end |
#each_column {|nil, value.required| ... } ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/sheetah/attribute_types/scalar.rb', line 40 def each_column return enum_for(:each_column) { 1 } unless block_given? yield nil, value.required self end |