lib/cultural_network/import/feature_importation.rb
# Up to four optional geocode types can be specified. For each geocode type the required columns are
# "i.geo_code_types.code"/"i.geo_code_types.name" (where i can range between 1 and 4) and
# "i.feature_geo_codes.geo_code_value".
# The following optional columns are also accepted:
# "i.feature_geo_codes.info_source.id"/"i.feature_geo_codes.info_source.code" and
# "i.feature_geo_codes.time_units.date".
Up to four optional geocode types can be specified.
Up to four optional geocode types can be specified .
def process_geocodes(n)
      1.upto(n) do |i|
        begin
          geocode_type = GeoCodeType.get_by_code_or_name(self.fields.delete("#{i}.geo_code_types.code"), self.fields.delete("#{i}.geo_code_types.name"))
        rescue Exception => e
          puts e.to_s
        end
        next if geocode_type.nil?
        geocode_value = self.fields.delete("#{i}.feature_geo_codes.geo_code_value")
        if geocode_value.blank?
          puts "Geocode value #{geocode_value} required for #{geocode_type.name}."
          next
        end
        geocodes = self.feature.geo_codes
        geocode = geocodes.find_by_geo_code_type_id(geocode_type.id)
        geocode = geocodes.create(:geo_code_type => geocode_type, :geo_code_value => geocode_value) if geocode.nil?
        if geocode.nil?
          puts "Couldn't associate #{geocode_value} to #{geocode_type} for feature #{self.feature.pid}"
          next
        end
        second_prefix = "#{i}.feature_geo_codes"
        0.upto(3) do |j|
          third_prefix = j==0 ? second_prefix : "#{second_prefix}.#{j}"
          self.add_date(third_prefix, geocode)
          self.add_info_source(third_prefix, geocode)
          self.add_note(third_prefix, geocode)
        end
      end
    end
def process_geocodes ( n ) 1 . upto ( n ) do | i | begin geocode_type = GeoCodeType . get_by_code_or_name ( self . fields . delete ( "#{i}.geo_code_types.code" ) , self . fields . delete ( "#{i}.geo_code_types.name" ) ) rescue Exception => e puts e . to_s end next if geocode_type . nil? geocode_value = self . fields . delete ( "#{i}.feature_geo_codes.geo_code_value" ) if geocode_value . blank? puts "Geocode value #{geocode_value} required for #{geocode_type.name}." next end geocodes = self . feature . geo_codes geocode = geocodes . find_by_geo_code_type_id ( geocode_type . id ) geocode = geocodes . create ( :geo_code_type => geocode_type , :geo_code_value => geocode_value ) if geocode . nil? if geocode . nil? puts "Couldn't associate #{geocode_value} to #{geocode_type} for feature #{self.feature.pid}" next end second_prefix = "#{i}.feature_geo_codes" 0 . upto ( 3 ) do | j | third_prefix = j == 0 ? second_prefix : "#{second_prefix}.#{j}" self . add_date ( third_prefix , geocode ) self . add_info_source ( third_prefix , geocode ) self . add_note ( third_prefix , geocode ) end end end
Up to four optional geocode types can be specified.
Up to four optional geocode types can be specified .
n
<not_specific>