class USAmap

@author salemine <info@salemine.com>

Public Class Methods

new(stats_h = {}, colors_h = {}) click to toggle source

@param [Hash] stats_h stats to plot by county FIPS value eg stats_h ['35001'] = 3 @param [Hash] colors_h colors to plot for numeric ranges eg colors_h [0..5] = '#CD5C5C'

# File lib/usamap.rb, line 8
def initialize(stats_h = {}, colors_h = {})
  @stats_h, @colors_h = stats_h, colors_h
end

Public Instance Methods

to_s() click to toggle source

Returns:

A colorized SVG (Scalable Vector Graphics) map of the USA

# File lib/usamap.rb, line 14
def to_s
  css = '' 
  @stats_h.each do |fips, val|
    colr = @colors_h.select { |range, hex| range.member?(val) }.values.first  
    css << ".c#{fips} {fill:#{colr}}\n"
  end
  svg = UsaCountiesSvg.svg
  css.empty? ? svg : svg.gsub!(/\/\*CSS insertion point\*\//, "/*CSS insertion point*/\n#{css}") 
end