json22d 0.5 → 0.6
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/json22d.rb +3 -1
- data/spec/json22d_spec.rb +25 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f62597a854e721433be608f3aa616672527b8d22
|
4
|
+
data.tar.gz: a7bd1843ab9323e86bf6132b4903564be1dfa0bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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-
|
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.
|
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
|