class Census::Geography

A Census geography

Constants

LEVELS
LEVEL_ALIAS

Attributes

contained_in[RW]
summary_level[RW]

Public Class Methods

new() click to toggle source
# File lib/rboc/geo.rb, line 20
def initialize
  @summary_level = {}
  @contained_in = {}
end

Public Instance Methods

summary_level=(lvl) click to toggle source

Sets the summary level to the specified value. If 'lvl' is a hash, it should only contain one element.

# File lib/rboc/geo.rb, line 28
def summary_level=(lvl)

  if lvl.is_a? Hash
    k, v = lvl.first
    k = LEVEL_ALIAS[k] if LEVEL_ALIAS[k] 
    @summary_level[k] = v
  else
    k = LEVEL_ALIAS[lvl] || lvl
    @summary_level[k] = '*'
  end
end
to_hash() click to toggle source
# File lib/rboc/geo.rb, line 40
def to_hash
  h = {}
  @summary_level['us'] = '*' if @summary_level.empty?

  k, v = @summary_level.first
  h['for'] = "#{k}:#{v}"

  unless @contained_in.empty?
    h['in'] = @contained_in.map {|k, v| "#{k}:#{v}"}.join("+")
  end

  h
end
to_s() click to toggle source

Returns the geography portion of the API GET string.

# File lib/rboc/geo.rb, line 56
def to_s
  URI.encode_www_form self.to_hash
end