Class: Census::Geography
- Inherits:
-
Object
- Object
- Census::Geography
- 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
-
#contained_in ⇒ Object
Returns the value of attribute contained_in.
-
#summary_level ⇒ Object
Returns the value of attribute summary_level.
Instance Method Summary collapse
-
#initialize ⇒ Geography
constructor
A new instance of Geography.
- #to_hash ⇒ Object
-
#to_s ⇒ Object
Returns the geography portion of the API GET string.
Constructor Details
#initialize ⇒ Geography
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_in ⇒ Object
Returns the value of attribute contained_in.
18 19 20 |
# File 'lib/rboc/geo.rb', line 18 def contained_in @contained_in end |
#summary_level ⇒ Object
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_hash ⇒ Object
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_s ⇒ Object
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 |