Class: SpatialFeatures::Importers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/spatial_features/importers/base.rb

Direct Known Subclasses

GeoJSON, KML, Shapefile

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, make_valid: false, tmpdir: nil, source_identifier: nil, feature_name: ->(record) { record.name }) ⇒ Base

Returns a new instance of Base.



15
16
17
18
19
20
21
22
23
# File 'lib/spatial_features/importers/base.rb', line 15

def initialize(data, make_valid: false, tmpdir: nil, source_identifier: nil, feature_name: ->(record) { record.name })
  @make_valid = make_valid
  @data = data
  @errors = []
  @warnings = []
  @tmpdir = tmpdir
  @source_identifier = source_identifier
  @feature_name = feature_name
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



6
7
8
# File 'lib/spatial_features/importers/base.rb', line 6

def errors
  @errors
end

#source_identifierObject

An identifier for the source of the features. Used to differentiate groups of features on the spatial model.



13
14
15
# File 'lib/spatial_features/importers/base.rb', line 13

def source_identifier
  @source_identifier
end

#warningsObject (readonly)

Non-fatal messages about parts of the source that could not be imported but did not prevent the remaining features from importing (e.g. unsupported elements). Unlike errors, warnings never abort the import.



11
12
13
# File 'lib/spatial_features/importers/base.rb', line 11

def warnings
  @warnings
end

Class Method Details

.create_all(data, **options) ⇒ Object

factory method that should always be used instead of new when creating importers returns an array of Importer::* objects



35
36
37
# File 'lib/spatial_features/importers/base.rb', line 35

def self.create_all(data, **options)
  [new(data, **options)]
end

Instance Method Details

#cache_keyObject



29
30
31
# File 'lib/spatial_features/importers/base.rb', line 29

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

#featuresObject



25
26
27
# File 'lib/spatial_features/importers/base.rb', line 25

def features
  @features ||= build_features
end