Class: Charta::Factory::Transformers::EwktTransformerChain

Inherits:
EwktTransformer
  • Object
show all
Defined in:
lib/charta/factory/transformers/ewkt_transformer_chain.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*transformers) ⇒ EwktTransformerChain

Returns a new instance of EwktTransformerChain.



22
23
24
# File 'lib/charta/factory/transformers/ewkt_transformer_chain.rb', line 22

def initialize(*transformers)
  @transformers = transformers
end

Instance Attribute Details

#transformersArray<EwktTransformer> (readonly)

Returns:



20
21
22
# File 'lib/charta/factory/transformers/ewkt_transformer_chain.rb', line 20

def transformers
  @transformers
end

Class Method Details

.buildObject



8
9
10
11
12
13
14
15
16
# File 'lib/charta/factory/transformers/ewkt_transformer_chain.rb', line 8

def build
  new(
    Transformers::FromGeoJsonTransformer.new,
    Transformers::FromWkbTransformer.new,
    Transformers::FromGmlTransformer.new,
    Transformers::FromKmlTransformer.new,
    Transformers::EwktPassthrough.new
  )
end

Instance Method Details

#handles?(value, format:) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/charta/factory/transformers/ewkt_transformer_chain.rb', line 27

def handles?(value, format:)
  transformers.any? { |t| t.handles?(value, format: format) }
end

#transform(value, srid: nil, format: nil) ⇒ String

Returns ewkt representation of value.

Parameters:

  • value (String, Hash)

Returns:

  • (String)

    ewkt representation of value

Raises:



33
34
35
36
37
38
# File 'lib/charta/factory/transformers/ewkt_transformer_chain.rb', line 33

def transform(value, srid: nil, format: nil)
  transformer = transformers.detect { |t| t.handles?(value, format: format) }
  raise TransformationError.new('Not handled') if transformer.nil?

  transformer.transform(value, srid: srid, format: format)
end