lib/openwfe/utils.rb in openwferu-0.9.3 vs lib/openwfe/utils.rb in openwferu-0.9.4

- old
+ new

@@ -209,8 +209,72 @@ def duration return (Time.now.to_f - @start) * 1000 end end + + # + # This method is used within the InFlowWorkItem and the CsvTable classes. + # + def OpenWFE.lookup_attribute (container, key) + + key, rest = pop_key(key) + value = container[key] + + return value unless rest + + return nil unless value + + return lookup_attribute(value, rest) + end + + # + # This method is used within the InFlowWorkItem and the CsvTable classes. + # + def OpenWFE.has_attribute? (container, key) + + key, rest = pop_key(key) + + if not rest + + return container.has_key?(key) \ + if container.respond_to?(:has_key?) + + return false + end + + return has_attribute?(rest, key) + end + + # + # This method is used within the InFlowWorkItem and the CsvTable classes. + # + def OpenWFE.set_attribute (container, key, value) + + i = key.rindex(".") + + if not i + container[key] = value + return + end + + container = lookup_attribute(container, key[0..i-1]) + container[key[i+1..-1]] = value + end + + protected + + def pop_key (key) + i = key.index(".") + return narrow(key), nil unless i + return narrow(key[0..i-1]), key[i+1..-1] + end + + def narrow (key) + return 0 if key == "0" + i = key.to_i + return i if i != 0 + return key + end end