json22d 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/json22d.rb +3 -1
  3. data/spec/json22d_spec.rb +25 -0
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b784be733972cbb47cd4ea2b690c3b934a65afd6
4
- data.tar.gz: d8f1a686b5874b77b16400d051fcc547b96a7739
3
+ metadata.gz: f62597a854e721433be608f3aa616672527b8d22
4
+ data.tar.gz: a7bd1843ab9323e86bf6132b4903564be1dfa0bc
5
5
  SHA512:
6
- metadata.gz: db66b220c6114cc63609c1c242fb5e3de2a9a83760d6f1fb9a394d03122dd3cd478b6d2ad7994c4e12f55e6c86b1be72114fd4b2b067a68d61ee6f52dacde844
7
- data.tar.gz: e6dc4e0286e433bc7511cfffba8b11c8a0a317919ad230bb5c514c5a4cfb23415b776f73e79d0e9d2d691ad1b75f7e94966444e9cc3a7a9623cbe808d143d8e8
6
+ metadata.gz: '09fe49f9261d1918cfa06660d8903ae26c83d65bcbc06e48fec33630d1d12595d84830cece6263d48fbe5d9c6120e9fe4e3f8e25a8175bbd9d48fb3022d53e9e'
7
+ data.tar.gz: 738d75d6b298503a26d1cbb6d41397c9695689e89d09903798a3d092add4262dd0ec6f863401531b3928aeb15a4adc5fc316e9a9a3dbdc8347ad7369d0b974a5
data/lib/json22d.rb CHANGED
@@ -5,7 +5,7 @@ require "active_support/inflector"
5
5
  module JSON22d
6
6
  extend self
7
7
 
8
- VERSION = "0.5"
8
+ VERSION = "0.6"
9
9
 
10
10
  def run(arr, config)
11
11
  arr = arr.to_json unless arr.is_a?(String)
@@ -173,6 +173,8 @@ module JSON22d
173
173
  end
174
174
  if name.include?("+")
175
175
  next acc << name.split("+").map { |k| hash[k] }.compact.join(" ")
176
+ elsif name.include?("|")
177
+ next acc << hash[name.split("|").detect { |k| hash[k] }]
176
178
  elsif n && sub_array.is_a?(Array)
177
179
  next acc << sub_array.join(n)
178
180
  else
data/spec/json22d_spec.rb CHANGED
@@ -141,6 +141,31 @@ describe "JSON22d" do
141
141
  end
142
142
  end
143
143
 
144
+ describe "selects first not-nil from two field results" do
145
+ before do
146
+ @arr = [{"i": "bar", "j": "foo"}]
147
+ @config = %w(i|j)
148
+ end
149
+
150
+ it "sets the correct header" do
151
+ header = JSON22d.run(@arr, @config).next
152
+ assert_equal ["i|j"], header
153
+ end
154
+
155
+ it "extracts the first of two fields" do
156
+ enum = JSON22d.run(@arr, @config)
157
+ enum.next # throw away header
158
+ assert_equal ["bar"], enum.next
159
+ end
160
+
161
+ it "extracts the second of two fields" do
162
+ @arr.first.delete(:i)
163
+ enum = JSON22d.run(@arr, @config)
164
+ enum.next # throw away header
165
+ assert_equal ["foo"], enum.next
166
+ end
167
+ end
168
+
144
169
  describe "joins multiple values within subarrays with given delim" do
145
170
  before do
146
171
  @arr = [{"i": ["bar", "blubb"]}, {"i": ["foo"]}]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json22d
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '0.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthias Geier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-15 00:00:00.000000000 Z
11
+ date: 2018-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  version: '0'
67
67
  requirements: []
68
68
  rubyforge_project:
69
- rubygems_version: 2.5.1
69
+ rubygems_version: 2.5.2.3
70
70
  signing_key:
71
71
  specification_version: 4
72
72
  summary: Transpile JSON into a flat structure