jsonl 0.1.4 → 0.1.5

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jsonl.rb +24 -0
  3. data/lib/jsonl/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 289abad3416cd6ca81bd909b3af37471f14f5349
4
- data.tar.gz: cdb34dab34bf5a8ab8cc3c5f52759f51202ddb6a
3
+ metadata.gz: c5f7d70cfded69042f7cbe8de1d6d14212f1ebb9
4
+ data.tar.gz: 8bca489cefcdcd01ef32e0a3f1d36cfb48bb6c5a
5
5
  SHA512:
6
- metadata.gz: fa4fe025ce3f75279df4798e637d0897e68f27e4e341a2d713b61f2e72e7f524c739f37187c274238acaadf3f10046ee70e747362c209453724c20bbe00a1b3a
7
- data.tar.gz: ce82b2fbed6941c2b2267c8f4bcefd1727cd7fec23d3a39532c554e914737cd4cf367c4f2c8663d3bcc1b508dd0b5f688ece7a5db383bb1dc4cd6f8b518b869a
6
+ metadata.gz: 5b64b0c1440aed50e2266923e446989fbaeca5b3bc2e93255870ab79ea64603ba5d1ed3c155d7dabd0d0c5c5b9e38287d93c87bb00bb6214565861e3fec8bf81
7
+ data.tar.gz: f60b828f378e39efc903cba0e30cef162480b74e444d0df770e5e60fe65a3916c3b07383f989c5da992dca3336c0c45db01237b0ddd160e8ec3812bf5e9d4e6f
@@ -4,6 +4,18 @@ require 'json'
4
4
  module JSONL
5
5
  module_function
6
6
 
7
+ # Generate a string formatted as JSONL from an array.
8
+ #
9
+ # ==== Attributes
10
+ #
11
+ # * +objs+ - an array consists of objects
12
+ # * +opts+ - options passes to `JSON.generate`
13
+ #
14
+ # ==== Exapmles
15
+ #
16
+ # users = User.all.map(&:attributes) #=> [{"id"=>1, "name"=>"Gilbert", ...}, {"id"=>2, "name"=>"Alexa", ...}, ...]
17
+ # generated = JSONL.generate(users)
18
+ #
7
19
  def generate(objs, opts = nil)
8
20
  unless objs.is_a?(Array)
9
21
  raise TypeError, "can't generate from #{objs.class}"
@@ -16,6 +28,18 @@ module JSONL
16
28
  generated.join("\n")
17
29
  end
18
30
 
31
+ # Parse JSONL string and return as an array.
32
+ #
33
+ # ==== Attributes
34
+ #
35
+ # * +source+ - a string formatted as JSONL
36
+ # * +opts+ - options passes to `JSON.parse`
37
+ #
38
+ # ==== Examples
39
+ #
40
+ # source = File.read('source.jsonl')
41
+ # parsed = JSONL.parse(source)
42
+ #
19
43
  def parse(source, opts = {})
20
44
  parsed = []
21
45
  source.each_line do |line|
@@ -1,3 +1,3 @@
1
1
  module JSONL
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - kami-zh