Class: Dentaku::AST::StringFunctions::Find

Inherits:
Function show all
Defined in:
lib/dentaku/ast/functions/string_functions.rb

Instance Method Summary collapse

Methods inherited from Function

#dependencies, get, register, register_class, registry

Methods inherited from Node

arity, #dependencies, precedence

Constructor Details

#initialize(*args) ⇒ Find

Returns a new instance of Find.



59
60
61
62
# File 'lib/dentaku/ast/functions/string_functions.rb', line 59

def initialize(*args)
  super
  @needle, @haystack = *@args
end

Instance Method Details

#value(context = {}) ⇒ Object



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

def value(context={})
  needle = @needle.value(context)
  needle = needle.to_s unless needle.is_a?(Regexp)
  haystack = @haystack.value(context).to_s
  pos = haystack.index(needle)
  pos && pos + 1
end