Class: Dentaku::AST::StringFunctions::Left

Inherits:
Base show all
Defined in:
lib/dentaku/ast/functions/string_functions.rb

Constant Summary

Constants inherited from Function

Function::DIG

Instance Method Summary collapse

Methods inherited from Base

#negative_argument_failure, #type

Methods inherited from Function

#dependencies, get, numeric, register, register_class, registry

Methods inherited from Node

arity, #dependencies, peek, precedence

Constructor Details

#initialize(*args) ⇒ Left

Returns a new instance of Left.



20
21
22
23
# File 'lib/dentaku/ast/functions/string_functions.rb', line 20

def initialize(*args)
  super
  @string, @length = *@args
end

Instance Method Details

#value(context = {}) ⇒ Object



25
26
27
28
29
30
# File 'lib/dentaku/ast/functions/string_functions.rb', line 25

def value(context = {})
  string = @string.value(context).to_s
  length = @length.value(context)
  negative_argument_failure('LEFT') if length < 0
  string[0, length]
end