Class: Dentaku::AST::StringFunctions::Mid
- 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) ⇒ Mid
constructor
A new instance of Mid.
- #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) ⇒ Mid
Returns a new instance of Mid.
72 73 74 75 |
# File 'lib/dentaku/ast/functions/string_functions.rb', line 72 def initialize(*args) super @string, @offset, @length = *@args end |
Class Method Details
.max_param_count ⇒ Object
68 69 70 |
# File 'lib/dentaku/ast/functions/string_functions.rb', line 68 def self.max_param_count 3 end |
.min_param_count ⇒ Object
64 65 66 |
# File 'lib/dentaku/ast/functions/string_functions.rb', line 64 def self.min_param_count 3 end |
Instance Method Details
#value(context = {}) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/dentaku/ast/functions/string_functions.rb', line 77 def value(context = {}) string = @string.value(context).to_s offset = Dentaku::AST::Function.numeric(@offset.value(context)).to_i negative_argument_failure('MID', 'offset') if offset < 0 length = Dentaku::AST::Function.numeric(@length.value(context)).to_i negative_argument_failure('MID') if length < 0 string[offset - 1, length].to_s end |