switched.rb
data structureFor example, if only the data for "Dana" for only 1951 and 1958 were loaded, years would look like this:
>> p years {1951=>{"Dana"=>[1277, 1076]}, 1958=>{"Dana"=>[1531, 2388]}}As a simple example of the mechanics, the following is a set of assignments that will produce the hash shown above.
years = {} years[1951] = {} years[1958] = {} years[1951]["Dana"] = [1277,1076] years[1958]["Dana"] = [1531,2388]
However, a solution would perhaps have only the line years = {}; everything else would use variables instead of literals.
My solution has a method that builds a hash for a given YEAR.txt file. I use it like this:
years[year] = load_year(year)
It's easy to drown in the data on a problem like this. You might start by having your loop that reads the YEAR.txt files discard data for everybody but "Dana" and then use p years to dump out the hash (assuming you use a hash named years). Next step: Have it also keep data for a male-only name. Then have it also keep data for a female-only name. Alternatively, you might edit down some data files to just a few lines of interest.