Class: CSVPlusPlus::Entities::FunctionCall

Inherits:
EntityWithArguments show all
Extended by:
T::Sig
Defined in:
lib/csv_plus_plus/entities/function_call.rb

Overview

A function call that can be either infix (A + B) or prefix (ADD(A, B))

Instance Attribute Summary collapse

Attributes inherited from EntityWithArguments

#arguments

Attributes inherited from Entity

#id, #type

Instance Method Summary collapse

Constructor Details

#initialize(id, arguments, infix: false) ⇒ FunctionCall

Returns a new instance of FunctionCall.

Parameters:

  • id (::String)

    The name of the function

  • arguments (Array<Entity>)

    The arguments to the function

  • infix (T::Boolean) (defaults to: false)

    Whether the function is infix



19
20
21
22
23
# File 'lib/csv_plus_plus/entities/function_call.rb', line 19

def initialize(id, arguments, infix: false)
  super(::CSVPlusPlus::Entities::Type::FunctionCall, id:, arguments:)

  @infix = infix
end

Instance Attribute Details

#infixboolean (readonly)

Whether or not this function call is infix (X * Y, A + B, etc)

Returns:

  • (boolean)

    the current value of infix



9
10
11
# File 'lib/csv_plus_plus/entities/function_call.rb', line 9

def infix
  @infix
end

Instance Method Details

#==(other) ⇒ boolean

Parameters:

Returns:

  • (boolean)


43
44
45
46
47
# File 'lib/csv_plus_plus/entities/function_call.rb', line 43

def ==(other)
  return false unless super

  other.is_a?(self.class) && @id == other.id && @infix == other.infix
end

#evaluate(runtime) ⇒ ::String

Parameters:

Returns:

  • (::String)


29
30
31
32
33
34
35
36
37
# File 'lib/csv_plus_plus/entities/function_call.rb', line 29

def evaluate(runtime)
  evaluated_arguments = evaluate_arguments(runtime)

  if @infix
    "(#{evaluated_arguments.join(" #{@id} ")})"
  else
    "#{@id.to_s.upcase}(#{evaluated_arguments.join(', ')})"
  end
end