lib/spiderfw/model/query_funcs.rb in spiderfw-0.5.9 vs lib/spiderfw/model/query_funcs.rb in spiderfw-0.5.10
- old
+ new
@@ -1,6 +1,26 @@
+module Spider; module Model
+
+end; end
+
module Spider; module QueryFuncs
+
+ def self.included(mod)
+ mod.extend(self)
+ super
+ end
+
+ def self.add_query_func(name, klass)
+ (class << self; self; end).module_eval do
+ define_method(name) do |*args|
+ return klass.new(*args)
+ end
+ end
+ define_method(name) do |*args|
+ return klass.new(*args)
+ end
+ end
class Expression
def initialize(string)
@string = string
@@ -25,10 +45,15 @@
end
class Function
attr_accessor :mapper_fields
+
+ def self.inherited(subclass)
+ cl_name = subclass.name.split('::')[-1].to_sym
+ Spider::QueryFuncs.add_query_func(cl_name, subclass)
+ end
def self.func_name
self.name =~ /::([^:]+)$/
return Inflector.underscore($1).to_sym
end
@@ -79,10 +104,22 @@
def elements
[@el1, @el2]
end
end
+
+ class NAryFunction < Function
+
+ def initialize(*elements)
+ @elements = elements
+ end
+
+ def elements
+ @elements
+ end
+
+ end
class CurrentDate < ZeroArityFunction
end
@@ -91,9 +128,23 @@
class Trim < UnaryFunction
end
class Subtract < BinaryFunction
+ end
+
+ class Concat < NAryFunction
+ end
+
+ class Substr < UnaryFunction
+ attr_reader :start, :length
+
+ def initialize(el, start, length=nil)
+ @el = el
+ @start = start
+ @length = length
+ end
+
end
end; end
\ No newline at end of file