ndjson 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/ndjson.rb +38 -0
  3. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: df27debf3ce08aea7d1dd33d9f3e8eae0a78e759
4
+ data.tar.gz: b13ed5fa3adcd278fab6e8d0e22f0629d0bb5080
5
+ SHA512:
6
+ metadata.gz: d7d4946b26050b922303918292840c53aa353ba52229a4297feb5e13eacf641bd860743bb59d77d76e0636c87bd9221319e4a1f5d4ecc623eea8b9187e6e825b
7
+ data.tar.gz: 6aabf094681977417ea5600e250ee4d6768744d7df305e09cf2c9766b4f0c945c5905340e378bc34c1e3d6d7c05f4b5909f01e2800fefe82db2a95cda0626a2e
@@ -0,0 +1,38 @@
1
+ require 'json'
2
+ require 'open-uri'
3
+
4
+ module NDJSON
5
+ class Parser
6
+
7
+ def initialize input
8
+ @input = if input.is_a? String
9
+ open(input)
10
+ else
11
+ input
12
+ end
13
+ end
14
+
15
+ def each &block
16
+ @input.each do |line|
17
+ json_line = JSON.parse(line)
18
+ yield json_line
19
+ end
20
+ end
21
+ end
22
+
23
+ class Generator
24
+
25
+ def initialize output
26
+ @output = if output.is_a? String
27
+ open(output, 'w')
28
+ else
29
+ output
30
+ end
31
+ end
32
+
33
+ def write obj
34
+ @output.puts JSON.generate(obj)
35
+ end
36
+
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ndjson
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Finn Pauls
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-30 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple NDJSON parser and generator
14
+ email: derfinn@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/ndjson.rb
20
+ homepage: https://github.com/ndjson/ndjson.rb
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.2.2
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: NDJSON parser and generator
44
+ test_files: []