Permalink
Browse files

some fixes for mongodb

  • Loading branch information...
1 parent 8621cc2 commit ac926f0c792593ad556c924b711f8041082d821d @nofxx committed Oct 31, 2012
Showing with 8 additions and 7 deletions.
  1. +8 −7 lib/geonames_local/models/mongodb.rb
@@ -18,6 +18,7 @@ class City < Geonames::Spot
field :ascii, type: String
field :slug, type: String
field :name, type: String
+ field :abbr, type: String
field :area
field :gid, type: Integer
field :zip, type: Integer
@@ -40,10 +41,6 @@ class City < Geonames::Spot
scope :ordered, order_by(name: 1)
- def abbr
- abbr || province ? province.abbr : country.abbr
- end
-
def set_defaults
self.country ||= province.try(:country)
self.slug ||= name.try(:downcase) # don't use slugize
@@ -59,22 +56,25 @@ def <=> other
end
def to_s
- "#{name}/#{province.abbr}"
+ "#{name}/#{abbr}"
end
def self.from_batch data
data.each do |city|
+ info "Writing city #{city.name}"
next unless city.country
city = new.parse(city)
city.country = city.province.country
- city.save!
+ city.save
end
end
def parse(spot)
- self.name, self.ascii = spot.code, spot.name, spot.ascii
+ self.name, self.ascii = spot.name, spot.ascii
self.code, self.gid = spot.code, spot.gid
self.province = Province.find_by(code: spot.province)
+ self.geom = [spot.lon, spot.lat]
+ self.abbr = province.abbr
self
end
@@ -104,6 +104,7 @@ class Province < Geonames::Spot
def self.from_batch data
data.each do |province|
+ info "Writing province #{province.name}"
next unless province.country
province = new.parse(province)
province.country = Country.find_by(abbr: /#{province.country}/i)

0 comments on commit ac926f0

Please sign in to comment.