Module: CSVPlusPlus::Entities::Builtins

Extended by:
ASTBuilder, T::Sig
Defined in:
lib/csv_plus_plus/entities/builtins.rb

Overview

Provides RuntimeValues for builtin functions and variables

Constant Summary collapse

VARIABLES =
::T.let(
  {
    # The number (integer) of the current cell. Starts at 1
    cellnum: runtime_value(->(p, _args) { number(p.cell_index + 1) }),

    # A reference to the current cell
    cellref: runtime_value(->(p, _args) { cell_ref(p.row_index, p.cell_index) }),

    # A reference to the row above
    rowabove: runtime_value(->(p, _args) { cell_ref([0, (p.row_index - 1)].max) }),

    # A reference to the row below
    rowbelow: runtime_value(->(p, _args) { cell_ref(p.row_index + 1) }),

    # The number (integer) of the current row.  Starts at 1
    rownum: runtime_value(->(p, _args) { number(p.rownum) }),

    # A reference to the current row
    rowref: runtime_value(->(p, _args) { cell_ref(p.row_index) })
  }.freeze,
  ::T::Hash[::Symbol, ::CSVPlusPlus::Entities::RuntimeValue]
)
FUNCTIONS =

TODO: A reference to a cell in a given row? TODO: check types of the args and throw a more friendly error?

::T.let(
  {
    # A reference to a cell above the current row
    cellabove: runtime_value(->(p, args) { cell_ref([0, (p.row_index - 1)].max, args[0].a1_ref.cell_index) }),

    # A reference to a cell in the current row
    celladjacent: runtime_value(->(p, args) { cell_ref(p.row_index, args[0].a1_ref.cell_index) }),

    # A reference to a cell below the current row
    cellbelow: runtime_value(->(p, args) { cell_ref(p.row_index + 1, args[0].a1_ref.cell_index) })
  }.freeze,
  ::T::Hash[::Symbol, ::CSVPlusPlus::Entities::RuntimeValue]
)

Class Method Summary collapse

Methods included from ASTBuilder

method_missing, respond_to_missing?

Class Method Details

.builtin_function?(fn_id) ⇒ T::Boolean

Is fn_id a builtin function?

Parameters:

  • fn_id (Symbol)

    The Function#id to check if it’s a runtime variable

Returns:

  • (T::Boolean)


59
60
61
# File 'lib/csv_plus_plus/entities/builtins.rb', line 59

def self.builtin_function?(fn_id)
  ::CSVPlusPlus::Entities::Builtins::FUNCTIONS.key?(fn_id)
end

.builtin_variable?(var_id) ⇒ Boolean

Is var_id a builtin variable?

Parameters:

  • var_id (Symbol)

    The Variable#id to check if it’s a runtime variable

Returns:



69
70
71
# File 'lib/csv_plus_plus/entities/builtins.rb', line 69

def self.builtin_variable?(var_id)
  ::CSVPlusPlus::Entities::Builtins::VARIABLES.key?(var_id)
end