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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 644b67a1de9540d0727b88c0b3ca6107cd327525
4
- data.tar.gz: ad0af101b590b480e3313230a1347fc9dfa53f35
3
+ metadata.gz: 289abad3416cd6ca81bd909b3af37471f14f5349
4
+ data.tar.gz: cdb34dab34bf5a8ab8cc3c5f52759f51202ddb6a
5
5
  SHA512:
6
- metadata.gz: fc0101d1c2f79ee38aad6c551245081be6ee40f8500af449473d59352a7fc16826981d5ca6e46830ba7d89580cbb9f0c5664586c67c00cac3f227b7089abfb7a
7
- data.tar.gz: 778ed4377de1f88b942ca9e0025af736502668b5be4e9c73e443aa418e4f04f767b808c77c1b785b9350c45f953bdb37a03e347b0e7af998440e5799f6029ac1
6
+ metadata.gz: fa4fe025ce3f75279df4798e637d0897e68f27e4e341a2d713b61f2e72e7f524c739f37187c274238acaadf3f10046ee70e747362c209453724c20bbe00a1b3a
7
+ data.tar.gz: ce82b2fbed6941c2b2267c8f4bcefd1727cd7fec23d3a39532c554e914737cd4cf367c4f2c8663d3bcc1b508dd0b5f688ece7a5db383bb1dc4cd6f8b518b869a
@@ -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|
@@ -1,3 +1,3 @@
1
1
  module JSONL
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -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 test_parsed_class
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 test_parsed_count
36
+ def test_parse_parsed_count
15
37
  assert_equal 4, @parsed.count
16
38
  end
17
39
 
18
- def test_parsed_equals_to_json_parse
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.3
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-15 00:00:00.000000000 Z
11
+ date: 2017-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler