Class: Decontaminate::Decoder::Tuple
- Inherits:
-
Object
- Object
- Decontaminate::Decoder::Tuple
- Defined in:
- lib/decontaminate/decoder/tuple.rb
Instance Attribute Summary collapse
-
#decoder ⇒ Object
readonly
Returns the value of attribute decoder.
-
#transformer ⇒ Object
readonly
Returns the value of attribute transformer.
-
#xpaths ⇒ Object
readonly
Returns the value of attribute xpaths.
Instance Method Summary collapse
- #decode(this, xml_node) ⇒ Object
-
#initialize(xpaths, decoder, transformer) ⇒ Tuple
constructor
A new instance of Tuple.
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
#decoder ⇒ Object (readonly)
Returns the value of attribute decoder.
4 5 6 |
# File 'lib/decontaminate/decoder/tuple.rb', line 4 def decoder @decoder end |
#transformer ⇒ Object (readonly)
Returns the value of attribute transformer.
4 5 6 |
# File 'lib/decontaminate/decoder/tuple.rb', line 4 def transformer @transformer end |
#xpaths ⇒ Object (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 |