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

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

Methods inherited from Function

#dependencies, get, numeric, register, register_class, registry

Methods inherited from Node

arity, #dependencies, peek, precedence

Constructor Details

#initialize(*args) ⇒ Find

Returns a new instance of Find.



80
81
82
83
# File 'lib/dentaku/ast/functions/string_functions.rb', line 80

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

Instance Method Details

#typeObject



93
94
95
# File 'lib/dentaku/ast/functions/string_functions.rb', line 93

def type
  :numeric
end

#value(context = {}) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/dentaku/ast/functions/string_functions.rb', line 85

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