jsonl 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 +4 -4
- data/lib/jsonl.rb +12 -0
- data/lib/jsonl/version.rb +1 -1
- data/test/jsonl_test.rb +25 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 289abad3416cd6ca81bd909b3af37471f14f5349
|
4
|
+
data.tar.gz: cdb34dab34bf5a8ab8cc3c5f52759f51202ddb6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa4fe025ce3f75279df4798e637d0897e68f27e4e341a2d713b61f2e72e7f524c739f37187c274238acaadf3f10046ee70e747362c209453724c20bbe00a1b3a
|
7
|
+
data.tar.gz: ce82b2fbed6941c2b2267c8f4bcefd1727cd7fec23d3a39532c554e914737cd4cf367c4f2c8663d3bcc1b508dd0b5f688ece7a5db383bb1dc4cd6f8b518b869a
|
data/lib/jsonl.rb
CHANGED
@@ -4,6 +4,18 @@ require 'json'
|
|
4
4
|
module JSONL
|
5
5
|
module_function
|
6
6
|
|
7
|
+
def generate(objs, opts = nil)
|
8
|
+
unless objs.is_a?(Array)
|
9
|
+
raise TypeError, "can't generate from #{objs.class}"
|
10
|
+
end
|
11
|
+
|
12
|
+
generated = []
|
13
|
+
objs.map do |obj|
|
14
|
+
generated << JSON.generate(obj, opts)
|
15
|
+
end
|
16
|
+
generated.join("\n")
|
17
|
+
end
|
18
|
+
|
7
19
|
def parse(source, opts = {})
|
8
20
|
parsed = []
|
9
21
|
source.each_line do |line|
|
data/lib/jsonl/version.rb
CHANGED
data/test/jsonl_test.rb
CHANGED
@@ -5,17 +5,39 @@ class JSONLTest < Minitest::Test
|
|
5
5
|
def setup
|
6
6
|
@source = File.read(File.expand_path('../fixtures/source.jsonl', __FILE__))
|
7
7
|
@parsed = JSONL.parse(@source)
|
8
|
+
@generated = JSONL.generate(@parsed)
|
8
9
|
end
|
9
10
|
|
10
|
-
def
|
11
|
+
def test_generate_type_error
|
12
|
+
e = assert_raises(TypeError) { JSONL.generate('invalid type') }
|
13
|
+
assert_equal 'can\'t generate from String', e.message
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_generate_generated_type
|
17
|
+
assert_instance_of String, @generated
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_generate_generated_count
|
21
|
+
assert_equal 4, @generated.split("\n").count
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_generate_generated_can_parse
|
25
|
+
assert JSONL.parse(@generated)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_generate_parsed_equals_to_the_original
|
29
|
+
assert_equal @parsed, JSONL.parse(@generated)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_parse_parsed_class
|
11
33
|
assert_instance_of Array, @parsed
|
12
34
|
end
|
13
35
|
|
14
|
-
def
|
36
|
+
def test_parse_parsed_count
|
15
37
|
assert_equal 4, @parsed.count
|
16
38
|
end
|
17
39
|
|
18
|
-
def
|
40
|
+
def test_parse_parsed_equals_to_json_parse
|
19
41
|
source = @source.split("\n")[0]
|
20
42
|
assert_equal JSON.parse(source), @parsed[0]
|
21
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kami-zh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|