lib/piglet/field/udf_expression.rb in piglet-0.2.5 vs lib/piglet/field/udf_expression.rb in piglet-0.3.0
- old
+ new
@@ -3,14 +3,19 @@
class UdfExpression
include Field
def initialize(ali4s, *args)
@alias, @args = ali4s, args
+ @predecessors = args.select { |arg| arg.respond_to? :field_alias }
end
- def to_s
- "#{@alias}(#{args_to_s(@args)})"
+ def to_s(inner=false)
+ if inner
+ "#{@alias}(#{args_to_inner_s(@args)})"
+ else
+ "#{@alias}(#{args_to_s(@args)})"
+ end
end
private
def args_to_s(arg)
@@ -19,9 +24,21 @@
"'#{escape(arg)}'"
when Enumerable
arg.map { |a| args_to_s(a) }.join(', ')
else
arg
+ end
+ end
+
+ def args_to_inner_s(arg)
+ if arg.is_a? String
+ "'#{escape(arg)}'"
+ elsif arg.is_a? Enumerable
+ arg.map { |a| args_to_inner_s(a) }.join(", ")
+ elsif arg.respond_to? :field_alias
+ arg.field_alias
+ else
+ arg.to_s
end
end
end
end
end
\ No newline at end of file