lib/pione/model/variable-table.rb in pione-0.1.4 vs lib/pione/model/variable-table.rb in pione-0.2.0
- old
+ new
@@ -130,15 +130,16 @@
# new variable table
def set(variable, new_value)
check_argument_type(variable, Variable)
check_argument_type(new_value, BasicModel)
if old_value = @table[variable]
- unless old_value.void? or new_value == old_value
+ unless old_value.nil? or old_value.void? or new_value == old_value
raise VariableBindingError.new(variable, new_value, old_value)
end
end
@table[variable] = new_value
+ return self
end
# Set a variable. This method overrides old variable value.
#
# @param variable [Variable]
@@ -160,15 +161,15 @@
# expanded string
def expand(str)
variables = to_hash
new_str = str.to_s.gsub(/\{(\$.+?)\}/) do
expr = DocumentTransformer.new.apply(DocumentParser.new.expr.parse($1))
- expr.eval(self).call_pione_method("textize").first.value
+ expr.eval(self).call_pione_method(self, "textize").first.value
end
new_str.gsub(/\<\?\s*(.+?)\s*\?\>/) do
expr = DocumentTransformer.new.apply(DocumentParser.new.expr.parse($1))
- expr.eval(self).call_pione_method("textize").first.value
+ expr.eval(self).call_pione_method(self, "textize").first.value
end
end
# Return key variables of the table.
#
@@ -187,10 +188,10 @@
# true if the string includes variables
def self.check_include_variable(str)
str = str.to_s
return true if /\{\$(.+?)\}/.match(str)
str.gsub(/\<\?\s*(.+?)\s*\?\>/) do
- expr = Transformer.new.apply(Parser.new.expr.parse($1))
+ expr = DocumentTransformer.new.apply(DocumentParser.new.expr.parse($1))
return true if expr.include_variable?
end
return false
end