Class: Dentaku::AST::StringFunctions::Substitute

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

Returns a new instance of Substitute.



147
148
149
150
# File 'lib/dentaku/ast/functions/string_functions.rb', line 147

def initialize(*args)
  super
  @original, @search, @replacement = *@args
end

Class Method Details

.max_param_countObject



143
144
145
# File 'lib/dentaku/ast/functions/string_functions.rb', line 143

def self.max_param_count
  3
end

.min_param_countObject



139
140
141
# File 'lib/dentaku/ast/functions/string_functions.rb', line 139

def self.min_param_count
  3
end

Instance Method Details

#value(context = {}) ⇒ Object



152
153
154
155
156
157
158
# File 'lib/dentaku/ast/functions/string_functions.rb', line 152

def value(context = {})
  original = @original.value(context).to_s
  search = @search.value(context)
  search = search.to_s unless search.is_a?(Regexp)
  replacement = @replacement.value(context).to_s
  original.sub(search, replacement)
end