lib/openwfe/util/dollar.rb in openwferu-0.9.15 vs lib/openwfe/util/dollar.rb in openwferu-0.9.16
- old
+ new
@@ -56,10 +56,12 @@
# Performs 'dollar substitution' on a piece of text with a given
# dictionary.
#
def OpenWFE.dsub (text, dict)
+ text = text.to_s
+
#puts "### text is >#{text}<"
#puts "### dict is of class #{dict.class.name}"
#return nil unless text
@@ -87,45 +89,50 @@
value = dict[key]
#puts "### value 0 is '#{value}'"
- if value
- value = value.to_s
+ value = if value
+ value.to_s
else
- if dict.has_key? key
- value = "false"
+ if dict.has_key?(key)
+ "false"
else
- value = ""
+ ""
end
end
#puts "### value 1 is '#{value}'"
#puts "pre is >#{text[0..i-1]}<"
#puts "post is >#{text[j+1..-1]}<"
- pre = ""
- if i > 0
- pre = text[0..i-1]
+ pre = if i > 0
+ text[0..i-1]
+ else
+ ""
end
- return dsub("#{pre}#{value}#{text[j+1..-1]}", dict)
+ dsub("#{pre}#{value}#{text[j+1..-1]}", dict)
end
def OpenWFE.unescape (text)
- return text.gsub("\\\\\\$\\{", "\\${")
+ text.gsub("\\\\\\$\\{", "\\${")
end
#
# Performs 'dollar substitution' on a piece of text with as input
# a flow expression and a workitem (fields and variables).
#
def OpenWFE.dosub (text, flow_expression, workitem)
- return dsub(text, FlowDict.new(flow_expression, workitem))
+ dsub(text, FlowDict.new(flow_expression, workitem))
end
+ #
+ # Wrapping a process expression and the current workitem as a
+ # Hash object ready for lookup at substitution time.
+ #
class FlowDict < Hash
def initialize (flow_expression, workitem)
@flow_expression = flow_expression
@workitem = workitem
@@ -147,11 +154,11 @@
return call_function(k) if p == 'c'
return call_ruby(k) if p == 'r'
# TODO : implement constant lookup
- return @workitem.lookup_attribute(key)
+ @workitem.lookup_attribute(key)
end
def has_key? (key)
p, k = extract_prefix(key)
@@ -166,18 +173,18 @@
return true if p == 'c'
return true if p == 'r'
# TODO : implement constant lookup
- return @workitem.has_attribute?(key)
+ @workitem.has_attribute?(key)
end
protected
def extract_prefix (key)
i = key.index(':')
return 'v', key if not i
- return key[0..0], key[i+1..-1]
+ [ key[0..0], key[i+1..-1] ]
end
def call_function (function_name)
#"function '#{function_name}' is not implemented"
"functions are not yet implemented"