Skip to content

Commit

Permalink
change Loader#load_countries to use the new mapping class. it's much …
Browse files Browse the repository at this point in the history
…tidier already
  • Loading branch information
joho committed Oct 25, 2009
1 parent bb2898f commit e5f583a
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions lib/geonames_rails/loader.rb
Expand Up @@ -23,23 +23,18 @@ def load_countries
# skip comments
next if line.match(/^#/) || line.match(/^iso/i)

country_elements = line.split("\t")
iso_code = country_elements[0]
country_mapping = Mapping::Country.new(line)

iso_code = country_mapping[:iso_code_two_letter]
c = Country.find_or_initialize_by_iso_code_two_letter(iso_code)
c.attributes = { :iso_code_two_letter => iso_code,
# [1] iso alpha3
:iso_code_three_letter => country_elements[1],
# [2] iso numeric
:iso_number => country_elements[2],
# [4] name
:name => country_elements[4],
# [5] capital
:capital => country_elements[5],
# [8] continent
:continent => country_elements[8],
# [16] Geoname id
:geonames_id => country_elements[16]
}

c.attributes = country_mapping.only(:iso_code_two_letter,
:iso_code_three_letter,
:iso_number,
:name,
:capital,
:continent,
:geonames_id)
c.save!
end
end
Expand Down

0 comments on commit e5f583a

Please sign in to comment.