kiba-common 0.5.0 → 0.6.0

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
  SHA256:
3
- metadata.gz: 925c701dd086d91b0f9b9222aa575a634a10c6a6d56e62c3edbbfad3d58d81f2
4
- data.tar.gz: ff158c83c13aa3378c9fc8b670aa9535867c68bad7c4f33b55c45e7cfd99ec57
3
+ metadata.gz: 1663d6106ac7cae429c6fba5a9bc3321222c957f44c21644eee77b73314f9e92
4
+ data.tar.gz: 92dfe90ee5c9f725ffad8635e4397a8da08bd86b879c1f56530afb5b0c206a39
5
5
  SHA512:
6
- metadata.gz: b4836e640abeddf2a3cde529ef12ec52e405705b782c7ad462b7fd05ffa193a52338162e7c40425570a8bf332275141a3e2ed0132e1f558536996e60c2f3ebfc
7
- data.tar.gz: 948bd196174bc02208438ebdb572bed401a01cfe461939728f3bb72c1770838dcd1d3ac48eeab36f04c25d0579ad445ef4d479f2103c6fc30257448ccb77f25b
6
+ metadata.gz: 6f87775082169e7ce4f6bff67c4ba30c3504b5df81dc0c47a4f752ffdf96e6b752b7e9362e174f9b9ca4808ee0c2c042a0c93f3f2809ba734badcb212951e77e
7
+ data.tar.gz: 47263dfa9ed01ac9ad266624478f9767c504be7e47b7546e9725e0c6f0652e75ab76a67ad08f70dca618f18142e47156f876efca732bc770315e734ba3a911a7
data/Changes.md CHANGED
@@ -1,10 +1,15 @@
1
1
  HEAD
2
2
  ----
3
3
 
4
+ 0.6.0
5
+ -----
6
+
7
+ - New: Kiba::Common::Transforms::EnumerableExploder will explode each enumerable row (responding to `#each`) into N rows.
8
+
4
9
  0.5.0
5
10
  -----
6
11
 
7
- - New: Kiba::Common::Sources::Enumerable allow to use any Ruby instance responding to `#each` (or a `Proc` returning such an instance) as a source for rows.
12
+ - New: Kiba::Common::Sources::Enumerable allows to use any Ruby instance responding to `#each` (or a `Proc` returning such an instance) as a source for rows.
8
13
 
9
14
  0.0.4
10
15
  -----
data/README.md CHANGED
@@ -38,6 +38,64 @@ You can pass a callable to make sure the evaluation will occur after your [pre-p
38
38
  source Kiba::Common::Sources::Enumerable, -> { Dir["input/*.json"] }
39
39
  ```
40
40
 
41
+ ### Kiba::Common::Transforms::EnumerableExploder
42
+
43
+ A transform calling `each` on input rows (assuming they are e.g. arrays of sub-rows) and yielding one output row per enumerated element.
44
+
45
+ Requirements: [Kiba v2](https://github.com/thbar/kiba/releases/tag/v2.0.0) with `StreamingRunner` enabled.
46
+
47
+ Usage:
48
+
49
+ ```ruby
50
+ require 'kiba-common/transforms/enumerable_exploder'
51
+
52
+ transform Kiba::Common::Transforms::EnumerableExploder
53
+ ```
54
+
55
+ For instance, this can help if you are reading XML/JSON documents from a source, and each input document contains multiple rows that you'd want to extract.
56
+
57
+ ```ruby
58
+ source Kiba::Common::Sources::Enumerable, -> { Dir["input/*.xml"] }
59
+
60
+ transform { |r| IO.binread(r) }
61
+ transform { |r| Nokogiri::XML(r) }
62
+ # this will return an array of XML elements
63
+ transform { |r| r.search('/orders') }
64
+ # this will explode the array (one order per output row)
65
+ transform Kiba::Common::Transforms::EnumerableExploder
66
+ ```
67
+
68
+ Similarly, if you have a CSV document as your input:
69
+
70
+ | po_number | buyers |
71
+ | ------------- | ------------- |
72
+ | 00001 | John:Mary:Sally |
73
+
74
+ and you want to reformat it to get this instead:
75
+
76
+ | po_number | buyer |
77
+ |-------------|---------|
78
+ | 00001 | John |
79
+ | 00001 | Mary |
80
+ | 00001 | Sally |
81
+
82
+ then you can explode them again with:
83
+
84
+ ```ruby
85
+ source MyCSVSource, filename: "input.csv"
86
+
87
+ transform do |row|
88
+ row.fetch(:buyers).split(':').map do |buyer|
89
+ {
90
+ po_number: row.fetch(:po_number),
91
+ buyer: buyer
92
+ }
93
+ end
94
+ end
95
+
96
+ transform Kiba::Common::Transforms::EnumerableExploder
97
+ ```
98
+
41
99
  ### Kiba::Common::Destinations::CSV
42
100
 
43
101
  A way to dump `Hash` rows as CSV.
@@ -0,0 +1,12 @@
1
+ module Kiba
2
+ module Common
3
+ module Transforms
4
+ class EnumerableExploder
5
+ def process(row)
6
+ row.each { |r| yield r }
7
+ nil
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  module Kiba
2
2
  module Common
3
- VERSION = '0.5.0'
3
+ VERSION = '0.6.0'
4
4
  end
5
5
  end
@@ -0,0 +1,24 @@
1
+ require_relative 'helper'
2
+ require 'kiba'
3
+ require_relative 'support/test_array_destination'
4
+ require 'kiba-common/transforms/enumerable_exploder'
5
+ require 'kiba/dsl_extensions/config'
6
+
7
+ class TestEnumerableExploderTransform < Minitest::Test
8
+ def test_exploder
9
+ output = []
10
+ input = [[1,2],[3,4,5]]
11
+
12
+ job = Kiba.parse do
13
+ extend Kiba::DSLExtensions::Config
14
+ config :kiba, runner: Kiba::StreamingRunner
15
+
16
+ source Kiba::Common::Sources::Enumerable, input
17
+ transform Kiba::Common::Transforms::EnumerableExploder
18
+ destination TestArrayDestination, output
19
+ end
20
+ Kiba.run(job)
21
+
22
+ assert_equal input.flatten, output
23
+ end
24
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kiba-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thibaut Barrère
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-23 00:00:00.000000000 Z
11
+ date: 2018-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kiba
@@ -91,11 +91,13 @@ files:
91
91
  - lib/kiba-common/dsl_extensions/logger.rb
92
92
  - lib/kiba-common/dsl_extensions/show_me.rb
93
93
  - lib/kiba-common/sources/enumerable.rb
94
+ - lib/kiba-common/transforms/enumerable_exploder.rb
94
95
  - lib/kiba-common/version.rb
95
96
  - test/helper.rb
96
97
  - test/support/assert_called.rb
97
98
  - test/support/test_array_destination.rb
98
99
  - test/test_csv_destination.rb
100
+ - test/test_enumerable_exploder_transform.rb
99
101
  - test/test_enumerable_source.rb
100
102
  - test/test_logger.rb
101
103
  - test/test_show_me.rb
@@ -128,6 +130,7 @@ test_files:
128
130
  - test/support/assert_called.rb
129
131
  - test/support/test_array_destination.rb
130
132
  - test/test_csv_destination.rb
133
+ - test/test_enumerable_exploder_transform.rb
131
134
  - test/test_enumerable_source.rb
132
135
  - test/test_logger.rb
133
136
  - test/test_show_me.rb