transformator 0.1.3 → 0.1.4

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: c8f70e695eed8b20aaa2dc6140156d64cf4cbf9c
4
- data.tar.gz: 67ec0bf5f788f0a418bfd33e8728e0f03001fb0e
3
+ metadata.gz: de79125e94963cf8f64a509a0ad23c1f33b6404e
4
+ data.tar.gz: bd978c37ba87a8a64c31240d48096f0a477d5b4a
5
5
  SHA512:
6
- metadata.gz: df811cbb7cce924d28988426d18bff1f765fb0545f55522e7560f96c9b3542b12766ac9bd590066b48a5c4fc5a1e6e7e04bcb7490cc34e6b2231f9d7b29b8508
7
- data.tar.gz: 865cbe1b2680803c4bcb004ea78748a244ec4964e7a188fe0bd04351be18eaa2cd2e9640d763af2bebf8a672c1d0c32a8d9967139b2383f35022c4174c41e680
6
+ metadata.gz: 05aa679773f11e290dab9b3de31499dfd452940b6670c0e8894689e1605f9eb04b5e2a264440a1679d6935c05006b9d782d379b23ecfb212e41db643f0385dba
7
+ data.tar.gz: c352e245758bbc162a87ac6c8d7b9fded4bb9f060972b7379303c23eb0696303810eb64f05488706af58253b26f37b583a8b3f13731d15c54e262152bd0bd6d4
@@ -74,7 +74,7 @@ module Transformator::Examples
74
74
  "control/recordid" => "id"
75
75
  }
76
76
  .each_pair do |from, to|
77
- find(_source, "_source/#{from}") do |element|
77
+ find(_source, from) do |element|
78
78
  hit << element(to, text: element.text)
79
79
  end
80
80
  end
@@ -76,6 +76,10 @@ class Transformator::Transformation
76
76
  #
77
77
  include Transformator::Dsl
78
78
 
79
+ def before_apply(options = {}, &block)
80
+ @rules.unshift({ callable: block, path: :none, type: :process}.merge(options))
81
+ end
82
+
79
83
  def output_format(format)
80
84
  @output_format = format.to_sym
81
85
  end
@@ -1,3 +1,3 @@
1
1
  module Transformator
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -45,6 +45,26 @@ describe Transformator::Transformation do
45
45
  expect(transformation.apply(to: source_xml)).to eq(transformed_xml)
46
46
  end
47
47
  end
48
+
49
+ describe "#before_apply" do
50
+ let(:transformation) do
51
+ described_class.new(data: "some_data") do
52
+ process :target do |target|
53
+ target << element("data", text: @foo)
54
+ end
55
+
56
+ # usually rules are executed in order as the are defined, but this one comes first
57
+ before_apply do
58
+ @foo = @data
59
+ end
60
+ end
61
+ end
62
+
63
+ it "executes the given block before applying the transformation" do
64
+ transformed_document = transformation.apply(to: nil, output_format: :ox_document)
65
+ expect(transformed_document.locate("data").first.text).to eq("some_data")
66
+ end
67
+ end
48
68
 
49
69
  describe "#output_format" do
50
70
  let(:transformation) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transformator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Sievers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-18 00:00:00.000000000 Z
11
+ date: 2014-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport