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.
- checksums.yaml +4 -4
- data/lib/jsonl.rb +24 -0
- data/lib/jsonl/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5f7d70cfded69042f7cbe8de1d6d14212f1ebb9
|
4
|
+
data.tar.gz: 8bca489cefcdcd01ef32e0a3f1d36cfb48bb6c5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b64b0c1440aed50e2266923e446989fbaeca5b3bc2e93255870ab79ea64603ba5d1ed3c155d7dabd0d0c5c5b9e38287d93c87bb00bb6214565861e3fec8bf81
|
7
|
+
data.tar.gz: f60b828f378e39efc903cba0e30cef162480b74e444d0df770e5e60fe65a3916c3b07383f989c5da992dca3336c0c45db01237b0ddd160e8ec3812bf5e9d4e6f
|
data/lib/jsonl.rb
CHANGED
@@ -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|
|
data/lib/jsonl/version.rb
CHANGED