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

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) ⇒ 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_countObject



68
69
70
# File 'lib/dentaku/ast/functions/string_functions.rb', line 68

def self.max_param_count
  3
end

.min_param_countObject



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