Class: Dentaku::AST::StringFunctions::Right

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

Constant Summary

Constants inherited from Function

Function::DIG

Instance Attribute Summary

Attributes inherited from Function

#args

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#negative_argument_failure, #type

Methods inherited from Function

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

Methods inherited from Node

arity, #dependencies, #name, precedence, resolve_class, #type

Constructor Details

#initialize(*args) ⇒ Right

Returns a new instance of Right.



50
51
52
53
# File 'lib/dentaku/ast/functions/string_functions.rb', line 50

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

Class Method Details

.max_param_countObject



46
47
48
# File 'lib/dentaku/ast/functions/string_functions.rb', line 46

def self.max_param_count
  2
end

.min_param_countObject



42
43
44
# File 'lib/dentaku/ast/functions/string_functions.rb', line 42

def self.min_param_count
  2
end

Instance Method Details

#value(context = {}) ⇒ Object



55
56
57
58
59
60
# File 'lib/dentaku/ast/functions/string_functions.rb', line 55

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