Class: Decontaminate::Decoder::Tuple

Inherits:
Object
  • Object
show all
Defined in:
lib/decontaminate/decoder/tuple.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xpaths, decoder, transformer) ⇒ Tuple

Returns a new instance of Tuple.



6
7
8
9
10
# File 'lib/decontaminate/decoder/tuple.rb', line 6

def initialize(xpaths, decoder, transformer)
  @xpaths = xpaths
  @decoder = decoder
  @transformer = transformer
end

Instance Attribute Details

#decoderObject (readonly)

Returns the value of attribute decoder.



4
5
6
# File 'lib/decontaminate/decoder/tuple.rb', line 4

def decoder
  @decoder
end

#transformerObject (readonly)

Returns the value of attribute transformer.



4
5
6
# File 'lib/decontaminate/decoder/tuple.rb', line 4

def transformer
  @transformer
end

#xpathsObject (readonly)

Returns the value of attribute xpaths.



4
5
6
# File 'lib/decontaminate/decoder/tuple.rb', line 4

def xpaths
  @xpaths
end

Instance Method Details

#decode(this, xml_node) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/decontaminate/decoder/tuple.rb', line 12

def decode(this, xml_node)
  xml_nodes = xpaths.map { |xpath| xml_node && xml_node.at_xpath(xpath) }
  tuple = xml_nodes.map do |element_node|
    decoder.decode this, element_node
  end

  tuple = this.instance_exec(*tuple, &transformer) if transformer

  tuple
end