Class: USAmap
Overview
Instance Method Summary collapse
-
#initialize(stats_h = {}, colors_h = {}) ⇒ USAmap
constructor
A new instance of USAmap.
-
#to_s ⇒ Object
Returns: A colorized SVG (Scalable Vector Graphics) map of the USA.
Methods included from UsaCountiesSvg
Constructor Details
#initialize(stats_h = {}, colors_h = {}) ⇒ USAmap
Returns a new instance of USAmap.
8 9 10 |
# File 'lib/usamap.rb', line 8 def initialize(stats_h = {}, colors_h = {}) @stats_h, @colors_h = stats_h, colors_h end |
Instance Method Details
#to_s ⇒ Object
Returns:
A colorized SVG (Scalable Vector Graphics) map of the USA
14 15 16 17 18 19 20 21 22 |
# 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 |