lib/sparklines.rb in sparklines-0.2.5 vs lib/sparklines.rb in sparklines-0.2.6

- old
+ new

@@ -1,5 +1,6 @@ + require 'RMagick' require 'mathn' =begin rdoc @@ -89,11 +90,11 @@ Licensed under the MIT license. =end module Sparklines - $VERSION = '0.2.5' + VERSION = '0.2.6' # Does the actually plotting of the graph. Calls the appropriate function based on the :type value passed. Defaults to 'smooth.' def Sparklines.plot(results=[], options={}) defaults = { :type => 'smooth', :height => 14, @@ -113,22 +114,23 @@ :has_min => false, :has_max => false, :has_last => false } - - # This symbol->string->symbol is kind of awkward. Is there a more elegant way? - + + # Have to do this to get around HashWithIndifferentAccess + options_sym = Hash.new options.keys.reverse.each do |key| - options[key.to_sym] = options[key] + options_sym[key.to_sym] = options[key] end - options = defaults.merge(options) + + options_sym = defaults.merge(options_sym) # Minimal normalization maximum_value = self.get_max_value(results).to_f # Call the appropriate function for actual plotting - self.send(options[:type], results, options, maximum_value) + self.send(options_sym[:type], results, options_sym, maximum_value) end # Writes a graph to disk with the specified filename, or "Sparklines.png" def Sparklines.plot_to_file(filename="sparklines.png", results=[], options={}) File.open( filename, 'wb' ) do |png|