Class: CSVPlusPlus::Entities::FunctionCall

Inherits:
EntityWithArguments show all
Extended by:
T::Sig
Includes:
HasIdentifier
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))

Constant Summary collapse

ArgumentsType =
type_member { { fixed: ::CSVPlusPlus::Entities::Entity } }

Instance Attribute Summary collapse

Attributes inherited from EntityWithArguments

#arguments

Instance Method Summary collapse

Methods included from HasIdentifier

#identifier

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



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

def initialize(id, arguments, infix: false)
  super(arguments:)

  @id = ::T.let(identifier(id), ::Symbol)
  @infix = infix
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#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:

  • other (BasicObject)

Returns:



57
58
59
60
61
62
63
64
# File 'lib/csv_plus_plus/entities/function_call.rb', line 57

def ==(other)
  case other
  when self.class
    @id == other.id && @infix == other.infix
  else
    false
  end
end

#evaluate(position) ⇒ ::String

Parameters:

  • position (Position)

Returns:

  • (::String)


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

def evaluate(position)
  evaluated_arguments = evaluate_arguments(position)

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