io-segmenter 0.6.0 → 0.7.0

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
  SHA256:
3
- metadata.gz: 794c025371c0f2a36e5648199101b20294bfb4ffb160c9d1c8d55d016115d660
4
- data.tar.gz: 821db4894a29799ab3f2a84a0574839470d9080bebeedfee8e368ef09f73b2ba
3
+ metadata.gz: ef640a71172e11880fce87b592533bc43d00e6ad4f05719d39528712bec96d8c
4
+ data.tar.gz: fc1a44127e69b4bf53108f4d5fa87e9a3f8cb1f715659ccb2093936a922449c4
5
5
  SHA512:
6
- metadata.gz: 5e4a7a3bfedac02138e053800bb619a5e38e5e19a4d3b623f7cb82abb04fddb9b3458d5c88bc0a07ffc8d1fa81350e5e8db227cb8cab8dd736d3dc585c127789
7
- data.tar.gz: 7a12973857ed46aaef093870ff5a008649500404bb7911966eb9258d5d7e96ac5d765988d721ec50ad9e71e3a4870fa48180a3f6bf7cdfb32eef5742291841d0
6
+ metadata.gz: c0a06f587dec25d94295597912ddc9668398ca14b79f24ce606979816447efd224578c3362ddcd7ea5131fec614ac77f990b56e2cd63d726a18b936a77b13981
7
+ data.tar.gz: 636c3bafcbf5991e8779aad2762fc8711e9d75d3784ff4a459fd73f6b3ccec0fc7bcf8585b54632f9d77b8d2cb1d1afec250b936c09fc3b343a26f5dcf8d3019
@@ -4,7 +4,9 @@
4
4
  class IOSegmenter
5
5
  include Enumerable
6
6
 
7
- def initialize(io, starting_char = '{', ending_char = '}', quote_char = '"', escape_char = '\\', max_read_size = 8192)
7
+ DEFAULT_READ_SIZE = 8192
8
+
9
+ def initialize(io, starting_char, ending_char, quote_char, escape_char, max_read_size=DEFAULT_READ_SIZE)
8
10
  @io = io
9
11
  @starting_char = starting_char
10
12
  @ending_char = ending_char
@@ -0,0 +1,8 @@
1
+ class File
2
+ def self.each_segment(file, *args, &block)
3
+ handle = open(file, 'rb')
4
+ handle.each_segment(*args, &block)
5
+ ensure
6
+ handle && handle.close
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ class IO
2
+ def each_segment(*args, &block)
3
+ IOSegmenter.new(self, *args).each(&block)
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JSON
4
+ def self.each_object(io, max_read_size=IOSegmenter::DEFAULT_READ_SIZE, &block)
5
+ IOSegmenter.new(io, '{', '}', '"', '\\', max_read_size).each do |segement|
6
+ yield parse(segement)
7
+ end
8
+ end
9
+
10
+ def self.each_string(io, max_read_size=IOSegmenter::DEFAULT_READ_SIZE)
11
+ IOSegmenter.new(io, '"', '"', nil, '\\', max_read_size).each do |segement|
12
+ yield segement[1, segement.size-2]
13
+ end
14
+ end
15
+
16
+ def self.each_item(io, max_read_size=IOSegmenter::DEFAULT_READ_SIZE)
17
+ io.read(1)
18
+ IOSegmenter.new(io, '[', ']', '"', '\\', max_read_size).each do |segement|
19
+ yield parse(segement)
20
+ end
21
+ end
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: io-segmenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Youch
@@ -17,6 +17,9 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/io-segmenter.rb
20
+ - lib/io-segmenter/core_ext/file.rb
21
+ - lib/io-segmenter/core_ext/io.rb
22
+ - lib/io-segmenter/core_ext/json.rb
20
23
  homepage: https://github.com/dougyouch/io-segemnter
21
24
  licenses: []
22
25
  metadata: {}