class SpatialFeatures::Importers::Base

Attributes

errors[R]

Public Class Methods

new(data, make_valid: false) click to toggle source
# File lib/spatial_features/importers/base.rb, line 8
def initialize(data, make_valid: false)
  @make_valid = make_valid
  @data = data
  @errors = []
end

Public Instance Methods

cache_key() click to toggle source
# File lib/spatial_features/importers/base.rb, line 18
def cache_key
  @cache_key ||= Digest::MD5.hexdigest(@data)
end
features() click to toggle source
# File lib/spatial_features/importers/base.rb, line 14
def features
  @features ||= build_features
end

Private Instance Methods

build_feature(record) click to toggle source
# File lib/spatial_features/importers/base.rb, line 42
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
build_features() click to toggle source
# File lib/spatial_features/importers/base.rb, line 24
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
each_record(&block) click to toggle source
# File lib/spatial_features/importers/base.rb, line 38
def each_record(&block)
  raise NotImplementedError, 'Subclasses should implement this method and yield objects that can be passed to #build_feature'
end