lib/table_fu.rb in table_fu-0.3.3 vs lib/table_fu.rb in table_fu-0.3.4
- old
+ new
@@ -274,25 +274,33 @@
# Then we test for a simple formatter method.
#
# And finally we return a empty string object or the value.
#
def to_s
- ret = if macro_value
- macro_value
+ ret = if macro?
+ macro_value.to_s
elsif @spreadsheet.formatting && format_method = @spreadsheet.formatting[column_name]
TableFu::Formatting.send(format_method, @datum) || ''
else
@datum.to_s || ''
end
ret.force_encoding("UTF-8") if RUBY_VERSION > "1.9"
ret
end
- # Returns the macro'd format if there is one
+ # Returns whether there is a macro format for this datum
#
# Returns:
- # The macro value if it exists, otherwise nil
+ # true if there is a macro format, false or nil otherwise
+ def macro?
+ @spreadsheet.formatting && @spreadsheet.formatting[@column_name].is_a?(Hash)
+ end
+
+ # Returns the macro'd format
+ #
+ # Returns:
+ # The macro value
def macro_value
# Grab the macro method first
# Then get a array of the values in the columns listed as arguments
# Splat the arguments to the macro method.
# Example:
@@ -300,17 +308,15 @@
# {'Total Appropriation' => :currency,
# 'AppendedColumn' => {'method' => 'append', 'arguments' => ['Projects','State']}}
#
# in the above case we handle the AppendedColumn in this method
- if @spreadsheet.formatting && @spreadsheet.formatting[@column_name].is_a?(Hash)
- method = @spreadsheet.formatting[@column_name]['method']
- arguments = @spreadsheet.formatting[@column_name]['arguments'].inject([]) do |arr,arg|
- arr << @row.column_for(arg)
- arr
- end
- TableFu::Formatting.send(method, *arguments)
+ method = @spreadsheet.formatting[@column_name]['method']
+ arguments = @spreadsheet.formatting[@column_name]['arguments'].inject([]) do |arr,arg|
+ arr << @row.column_for(arg)
+ arr
end
+ TableFu::Formatting.send(method, *arguments)
end
# Returns the raw value of a datum
#
# Returns:
\ No newline at end of file