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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#negative_argument_failure, #type

Methods inherited from Function

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

Methods inherited from Node

arity, #dependencies, peek, precedence, #type

Constructor Details

#initialize(*args) ⇒ Left

Returns a new instance of Left.



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

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

Class Method Details

.max_param_countObject



24
25
26
# File 'lib/dentaku/ast/functions/string_functions.rb', line 24

def self.max_param_count
  2
end

.min_param_countObject



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

def self.min_param_count
  2
end

Instance Method Details

#value(context = {}) ⇒ Object



33
34
35
36
37
38
# File 'lib/dentaku/ast/functions/string_functions.rb', line 33

def value(context = {})
  string = @string.value(context).to_s
  length = Dentaku::AST::Function.numeric(@length.value(context)).to_i
  negative_argument_failure('LEFT') if length < 0
  string[0, length]
end