transformator 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5da1c0998ecdd4c7a4f6b862011ef029244cfd06
4
- data.tar.gz: 6e993b4c18f491a851b4e6238aa8d085045e07b7
3
+ metadata.gz: c8f70e695eed8b20aaa2dc6140156d64cf4cbf9c
4
+ data.tar.gz: 67ec0bf5f788f0a418bfd33e8728e0f03001fb0e
5
5
  SHA512:
6
- metadata.gz: 4ff77077de278799b5088e0b6df6db3746e34806ab8b449405419cac1d08d2350beb3d9ab979cbb87903b6282cf6dc1cd65037478cb0ac5157eaee590a6dcfd2
7
- data.tar.gz: 87b3444767fd835166b06885a036f20153f7e09d47ebf3793057f603d6f76e58c8b04b7b9ae53eec1629a25fff606b0658028b54a56f52320238043842e890eb
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 do process source => source, target => target or target => source
28
- _source = options[:source] == :target ? target : source
29
- _target = options[:target] == :source ? source : target
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)
@@ -1,3 +1,3 @@
1
1
  module Transformator
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transformator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Sievers