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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#negative_argument_failure

Methods inherited from Function

#deferred_args, #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.



120
121
122
123
# File 'lib/dentaku/ast/functions/string_functions.rb', line 120

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

Class Method Details

.max_param_countObject



116
117
118
# File 'lib/dentaku/ast/functions/string_functions.rb', line 116

def self.max_param_count
  2
end

.min_param_countObject



112
113
114
# File 'lib/dentaku/ast/functions/string_functions.rb', line 112

def self.min_param_count
  2
end

Instance Method Details

#typeObject



133
134
135
# File 'lib/dentaku/ast/functions/string_functions.rb', line 133

def type
  :numeric
end

#value(context = {}) ⇒ Object



125
126
127
128
129
130
131
# File 'lib/dentaku/ast/functions/string_functions.rb', line 125

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