transformator 0.1.2 → 0.1.3
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 +4 -4
- data/lib/transformator/transformation.rb +14 -3
- data/lib/transformator/version.rb +1 -1
- data/spec/transformator/transformation_spec.rb +18 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8f70e695eed8b20aaa2dc6140156d64cf4cbf9c
|
4
|
+
data.tar.gz: 67ec0bf5f788f0a418bfd33e8728e0f03001fb0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df811cbb7cce924d28988426d18bff1f765fb0545f55522e7560f96c9b3542b12766ac9bd590066b48a5c4fc5a1e6e7e04bcb7490cc34e6b2231f9d7b29b8508
|
7
|
+
data.tar.gz: 865cbe1b2680803c4bcb004ea78748a244ec4964e7a188fe0bd04351be18eaa2cd2e9640d763af2bebf8a672c1d0c32a8d9967139b2383f35022c4174c41e680
|
@@ -24,9 +24,20 @@ class Transformator::Transformation
|
|
24
24
|
path = rule[:path]
|
25
25
|
type = rule[:type]
|
26
26
|
|
27
|
-
# allow user
|
28
|
-
_source =
|
29
|
-
|
27
|
+
# allow user to set source/target freely
|
28
|
+
_source =
|
29
|
+
if (source_callable = rule[:source]).respond_to?(:call)
|
30
|
+
source_callable.call
|
31
|
+
else
|
32
|
+
source
|
33
|
+
end
|
34
|
+
|
35
|
+
_target =
|
36
|
+
if (target_callable = rule[:target]).respond_to?(:call)
|
37
|
+
target_callable.call
|
38
|
+
else
|
39
|
+
target
|
40
|
+
end
|
30
41
|
|
31
42
|
if type == :process
|
32
43
|
if path.is_a?(Array)
|
@@ -59,6 +59,24 @@ describe Transformator::Transformation do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
describe "#process" do
|
62
|
+
context "when source responds to call" do
|
63
|
+
let(:transformation) do
|
64
|
+
described_class.new do
|
65
|
+
process :none do
|
66
|
+
@foo = element("foo") << element("bar", text: "muff")
|
67
|
+
end
|
68
|
+
|
69
|
+
process "*", source: -> { @foo } do |element, target|
|
70
|
+
target << element
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
it "executes the rule with the callable result as the source" do
|
76
|
+
expect(transformation.apply(to: nil, output_format: :ox_document).locate("bar").first.text).to eq("muff")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
62
80
|
context "when called with the special path :document" do
|
63
81
|
it "provides the whole input document to the block" do
|
64
82
|
transformation = described_class.new do
|