Class: Dentaku::AST::StringFunctions::Mid

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, #type

Constructor Details

#initialize(*args) ⇒ Mid

Returns a new instance of Mid.



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

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

Instance Method Details

#value(context = {}) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/dentaku/ast/functions/string_functions.rb', line 61

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