At present, you pass in fields that are just the codes listed in the Census reference handbook. This provides reliability, but it's not very Rubyish.
I think it's possible to let people specify field components by text, which are looked up in a YAML file / Hash to construct the field code.
Example:
field = Field.new(:total_population, :total, :white, :total)
field.code
# => 'P0010001'
@client.find( field, county: 'Suffolk', state: 'MA' )
# => [{"P0010001"=>"722023", "name"=>"Suffolk County", "state"=>"25", "county"=>"025"}]
# or specify the table name directly, which returns the first field for that table
@client.find( :total_population, county: 'Suffolk', state: 'MA' )
# => [{"P0010001"=>"722023", "name"=>"Suffolk County", "state"=>"25", "county"=>"025"}]
field_hh = Field.new(:household_type, :other_family)
field_hh.code
#=> 'P0180004'
Field Construction
Field codes appear to have a highly structured construction, but the principles behind it are not clearly laid out anywhere in the census docs. From cursory research, they look like:
P001A0001
Table Type: P
Table Indicator: 001 (in Census docs, it's just P1. Any table indicator is formatted with a %3d.
(Optional) Race Indicator: A
Field Code:
Or, as an object (looks like YAML a little...):
P: Population
001: Total (Population)
A: White
0001: Total
At present, you pass in fields that are just the codes listed in the Census reference handbook. This provides reliability, but it's not very Rubyish.
I think it's possible to let people specify field components by text, which are looked up in a YAML file / Hash to construct the field code.
Example:
Field Construction
Field codes appear to have a highly structured construction, but the principles behind it are not clearly laid out anywhere in the census docs. From cursory research, they look like:
P001A0001
%3d
.Or, as an object (looks like YAML a little...):