Class: Dentaku::AST::StringFunctions::Left
- Defined in:
- lib/dentaku/ast/functions/string_functions.rb
Constant Summary
Constants inherited from Function
Instance Attribute Summary
Attributes inherited from Function
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(*args) ⇒ Left
constructor
A new instance of Left.
- #value(context = {}) ⇒ Object
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) ⇒ 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_count ⇒ Object
24 25 26 |
# File 'lib/dentaku/ast/functions/string_functions.rb', line 24 def self.max_param_count 2 end |
.min_param_count ⇒ Object
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 |