Class: CSVPlusPlus::Entities::RuntimeValue

Inherits:
Entity
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/csv_plus_plus/entities/runtime_value.rb

Overview

A runtime value. These are values which can be materialized at any point via the resolve_fn which will provide a value depending on the Runtime‘s current state.

Constant Summary collapse

ResolveFn =
::T.type_alias do
  ::T.proc.params(
    position: ::CSVPlusPlus::Runtime::Position,
    arguments: ::T::Enumerable[::CSVPlusPlus::Entities::Entity]
  ).returns(::CSVPlusPlus::Entities::Entity)
end

Instance Method Summary collapse

Methods inherited from Entity

#==

Constructor Details

#initialize(resolve_fn) ⇒ RuntimeValue

Returns a new instance of RuntimeValue.

Parameters:

  • resolve_fn (lambda)

    A lambda that is called when the runtime value is resolved



26
27
28
29
# File 'lib/csv_plus_plus/entities/runtime_value.rb', line 26

def initialize(resolve_fn)
  @resolve_fn = resolve_fn
  super()
end

Instance Method Details

#call(position, arguments) ⇒ Object

Using the @resolve_fn, evaluate this runtime value into an Entity that can be later evaluated



38
39
40
# File 'lib/csv_plus_plus/entities/runtime_value.rb', line 38

def call(position, arguments)
  @resolve_fn.call(position, arguments)
end

#evaluate(_position) ⇒ Entities::Entity

Given the current runtime, call @resolve_fn to produce a value

Parameters:

  • _position (Position)

Returns:



48
49
50
51
52
53
# File 'lib/csv_plus_plus/entities/runtime_value.rb', line 48

def evaluate(_position)
  # TODO: we can do a check on arguments here and make sure that the RuntimeValue is being called
  # with the number of arguments it requires
  # @resolve_fn.call(position, ::T.must(arguments)).evaluate(position)
  '(runtime value)'
end