Class: Census::Geography

Inherits:
Object
  • Object
show all
Defined in:
lib/rboc/geo.rb

Overview

A Census geography

Constant Summary collapse

LEVELS =
[
  'us', 'region', 'division', 'state', 'county', 'tract'
]
LEVEL_ALIAS =
{
  'regions' => 'region',
  'divisions' => 'division',
  'states' => 'state',
  'counties' => 'county',
  'tracts' => 'tract',
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGeography

Returns a new instance of Geography.



20
21
22
23
# File 'lib/rboc/geo.rb', line 20

def initialize
  @summary_level = {}
  @contained_in = {}
end

Instance Attribute Details

#contained_inObject

Returns the value of attribute contained_in.



18
19
20
# File 'lib/rboc/geo.rb', line 18

def contained_in
  @contained_in
end

#summary_levelObject

Returns the value of attribute summary_level.



18
19
20
# File 'lib/rboc/geo.rb', line 18

def summary_level
  @summary_level
end

Instance Method Details

#to_hashObject



40
41
42
43
44
45
46
47
48
49
50
51
52
# 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_sObject

Returns the geography portion of the API GET string.



56
57
58
# File 'lib/rboc/geo.rb', line 56

def to_s
  URI.encode_www_form self.to_hash
end