transformator 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b18762ea7ff4419e08195d18ff1ca6b839985d9
|
4
|
+
data.tar.gz: 029f31bedd8f0a5e8a8667f26ef556a1da31688a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c85e2ab36e07e2f1d4a03665457c89de42d4e8581b175db9d96da788d49d3ede4666d465655ef6ad2556efa466a4c75d1863829707b9a5ceb207a6ea0bf9958
|
7
|
+
data.tar.gz: b75ea62ffcaac500613564f1a95b29df6a161bbb801ad6489c2a60f456705d6f7bc91a3573f17222a6f0b88f60cf63713176c6ae0016f758c8ad7bb1f616950b
|
@@ -3,6 +3,11 @@ require "transformator/dsl"
|
|
3
3
|
|
4
4
|
class Transformator::Transformation
|
5
5
|
def initialize(options = {}, &block)
|
6
|
+
# make it possible to initialize a transformation with external data
|
7
|
+
options.each_pair do |key, value|
|
8
|
+
instance_variable_set "@#{key}".to_sym, value
|
9
|
+
end
|
10
|
+
|
6
11
|
@rules = []
|
7
12
|
self.instance_eval(&block) if block
|
8
13
|
end
|
@@ -16,6 +16,25 @@ describe Transformator::Transformation do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "#new" do
|
19
|
+
context "when called with an options hash" do
|
20
|
+
let(:transformed_xml) do
|
21
|
+
<<-xml.strip_heredoc
|
22
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
23
|
+
<muff>value1</muff>
|
24
|
+
xml
|
25
|
+
end
|
26
|
+
|
27
|
+
it "provides each key as an instance variable inside the transformation" do
|
28
|
+
transformation = described_class.new(option1: "value1") do
|
29
|
+
process "foo/bar" do |element, target|
|
30
|
+
target << element("muff", text: @option1)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
expect(transformation.apply(to: source_xml)).to eq(transformed_xml)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
19
38
|
it "can be called with a block, containing the mapping described by the dsl" do
|
20
39
|
transformation = described_class.new do
|
21
40
|
process "foo/bar" do |element, target|
|