Class: Sheetah::AttributeTypes::Scalar

Inherits:
Object
  • Object
show all
Includes:
Sheetah::AttributeType
Defined in:
lib/sheetah/attribute_types/scalar.rb

Overview

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Scalar

Returns a new instance of Scalar.

Parameters:

  • value (Value)

    The value of the scalar.

See Also:



30
31
32
# File 'lib/sheetah/attribute_types/scalar.rb', line 30

def initialize(value)
  @value = value
end

Class Method Details

.buildScalar

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.

Returns:

  • (Scalar)

    a frozen instance



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

Yields:

  • (nil, value.required)

See Also:



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