lib/ruote/exp/ro_attributes.rb in ruote-2.1.11 vs lib/ruote/exp/ro_attributes.rb in ruote-2.2.0
- old
+ new
@@ -1,7 +1,7 @@
#--
-# Copyright (c) 2005-2010, John Mettraux, jmettraux@gmail.com
+# Copyright (c) 2005-2011, John Mettraux, jmettraux@gmail.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@@ -24,30 +24,30 @@
module Ruote::Exp
#
- # Those methods are mixed in FlowExpression. They were put here to offload
+ # Those methods are added in FlowExpression. They were put here to offload
# FlowExpression and especially, to gather them around their attribute topic.
#
class FlowExpression
# Given a list of attribute names, returns the first attribute name for
# which there is a value.
#
- def has_attribute (*args)
+ def has_attribute(*args)
args.each { |a| a = a.to_s; return a if attributes[a] != nil }
nil
end
alias :has_att :has_attribute
# Looks up the value for attribute n.
#
- def attribute (n, workitem=h.applied_workitem, options={})
+ def attribute(n, workitem=h.applied_workitem, options={})
n = n.to_s
default = options[:default]
escape = options[:escape]
@@ -70,11 +70,11 @@
# Returns the value for attribute 'key', this value should be present
# in the array list 'values'. If not, the default value is returned.
# By default, the default value is the first element of 'values'.
#
- def att (key, values, opts={})
+ def att(key, values, opts={})
default = opts[:default] || values.first
val = attribute(key)
val = val.to_s if val
@@ -90,20 +90,20 @@
end
# prefix = 'on' => will lookup on, on_val, on_value, on_v, on_var,
# on_variable, on_f, on_fld, on_field...
#
- def lookup_val_prefix (prefix, att_options={})
+ def lookup_val_prefix(prefix, att_options={})
lval(
[ prefix ] + [ 'val', 'value' ].map { |s| "#{prefix}_#{s}" },
%w[ v var variable ].map { |s| "#{prefix}_#{s}" },
%w[ f fld field ].map { |s| "#{prefix}_#{s}" },
att_options)
end
- def lookup_val (att_options={})
+ def lookup_val(att_options={})
lval(
VV,
s_cartesian(%w[ v var variable ], VV),
s_cartesian(%w[ f fld field ], VV),
@@ -111,11 +111,11 @@
end
# Returns a Hash containing all attributes set for an expression with
# their values resolved.
#
- def compile_atts (opts={})
+ def compile_atts(opts={})
attributes.keys.inject({}) { |r, k|
r[k] = attribute(k, h.applied_workitem, opts)
r
}
@@ -125,11 +125,11 @@
#
# Useful for things like
#
# set "f:${v:field_name}" => "${v:that_variable}"
#
- def expand_atts (opts={})
+ def expand_atts(opts={})
attributes.keys.inject({}) { |r, k|
kk = @context.dollar_sub.s(k, self, h.applied_workitem)
r[kk] = attribute(k, h.applied_workitem, opts)
r
@@ -146,11 +146,13 @@
#
# attribute_text()
#
# will yield 'alpha'.
#
- def attribute_text (workitem=h.applied_workitem)
+ # Note : an empty text returns '', not the nil value.
+ #
+ def attribute_text(workitem=h.applied_workitem)
text = attributes.keys.find { |k| attributes[k] == nil }
@context.dollar_sub.s(text.to_s, self, workitem)
end
@@ -165,15 +167,15 @@
# Val and Value (Sense and Sensibility ?)
#
VV = %w[ val value ]
- def s_cartesian (a0, a1)
+ def s_cartesian(a0, a1)
a0.inject([]) { |a, e0| a + a1.collect { |e1| "#{e0}_#{e1}" } }
end
- def lval (vals, vars, flds, att_options)
+ def lval(vals, vars, flds, att_options)
if k = has_att(*vals)
attribute(k, h.applied_workitem, att_options)