Sha256: de713b616010fd09fceb3ff95ef1b1d1aa3c0876ff7964518bad63287b9d12f4

Contents?: true

Size: 1.1 KB

Versions: 67

Compression:

Stored size: 1.1 KB

Contents

require 'digest/md5'

module SpatialFeatures
  module Importers
    class Base
      attr_reader :errors

      def initialize(data, make_valid: false)
        @make_valid = make_valid
        @data = data
        @errors = []
      end

      def features
        @features ||= build_features
      end

      def cache_key
        @cache_key ||= Digest::MD5.hexdigest(@data)
      end

      private

      def build_features
        new_features = []

        each_record do |record|
          begin
            new_features << build_feature(record)
          rescue => e
            @errors << e.message
          end
        end

        return new_features
      end

      def each_record(&block)
        raise NotImplementedError, 'Subclasses should implement this method and yield objects that can be passed to #build_feature'
      end

      def build_feature(record)
        Feature.new(:name => record.name, :metadata => record.metadata, :feature_type => record.feature_type, :geog => record.geog, :make_valid => @make_valid)
      end
    end
  end

  # EXCEPTIONS

  class ImportError < StandardError; end
end

Version data entries

67 entries across 67 versions & 1 rubygems

Version Path
spatial_features-2.17.2 lib/spatial_features/importers/base.rb
spatial_features-2.17.1 lib/spatial_features/importers/base.rb
spatial_features-2.17.0 lib/spatial_features/importers/base.rb
spatial_features-2.16.0 lib/spatial_features/importers/base.rb
spatial_features-2.15.1 lib/spatial_features/importers/base.rb
spatial_features-2.15.0 lib/spatial_features/importers/base.rb
spatial_features-2.14.1 lib/spatial_features/importers/base.rb
spatial_features-2.14.0 lib/spatial_features/importers/base.rb
spatial_features-2.13.0 lib/spatial_features/importers/base.rb
spatial_features-2.12.3 lib/spatial_features/importers/base.rb
spatial_features-2.12.2 lib/spatial_features/importers/base.rb
spatial_features-2.12.1 lib/spatial_features/importers/base.rb
spatial_features-2.12.0 lib/spatial_features/importers/base.rb
spatial_features-2.11.1 lib/spatial_features/importers/base.rb
spatial_features-2.11.0 lib/spatial_features/importers/base.rb
spatial_features-2.10.9 lib/spatial_features/importers/base.rb
spatial_features-2.10.8 lib/spatial_features/importers/base.rb
spatial_features-2.10.7 lib/spatial_features/importers/base.rb
spatial_features-2.10.6 lib/spatial_features/importers/base.rb
spatial_features-2.10.5 lib/spatial_features/importers/base.rb