io-segmenter 0.7.1 → 0.7.2

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 +4 -4
  2. data/lib/io-segmenter.rb +11 -4
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9755c7c1fbe0f11cd76db5a6762eebbd3dcfe8ffa107f3f61ed06c8541fe12a
4
- data.tar.gz: c4ff334cbfe863b363f687f5edecc7dc561a71003bdc554b7dfc50f6b33452cb
3
+ metadata.gz: 41882b615cb02ee0e614e868104006e98fafb0ba0b96adb0d55431b13d285116
4
+ data.tar.gz: 86655c3225adc2bb178d3a31cb4b4cd37f37d538b419316eddd56e24b3059f1a
5
5
  SHA512:
6
- metadata.gz: 9b2b6d61a11cf34d5da05cdc4fa4136745bb905e74a8696f51e0d08e5fd38def6eabb5339ad68c55d5dab88777bdb435f05a1a28474c529a027712dff984f811
7
- data.tar.gz: 85ca1aa179cdf8161ed72063341a841f30b1384e6d7654aa993d62b1508be7a5cf328ee4ac0fcb53f049a131cf3b4ae80feb9725b6616c89f666c5035f8c3439
6
+ metadata.gz: cac57f6a5ac8b5e345867452acc553f184980541bc0328291eca69261c05471dd9631a5585540eed1bbf4512d062a4abc6b1c97d7f84e901c8cb5049e3b4c722
7
+ data.tar.gz: 478d2436eb58f002019125135351adaa69eb2c1611cbf610ace311d2ee715f76beb7b25b81b578eea271beeee31c122b1881c88a1664afe1813b5aad659b1b0a
data/lib/io-segmenter.rb CHANGED
@@ -6,6 +6,8 @@ class IOSegmenter
6
6
 
7
7
  DEFAULT_READ_SIZE = 8192
8
8
 
9
+ attr_reader :buffer
10
+
9
11
  def initialize(io, starting_char, ending_char, quote_char, escape_char, max_read_size=DEFAULT_READ_SIZE)
10
12
  @io = io
11
13
  @starting_char = starting_char
@@ -24,19 +26,24 @@ class IOSegmenter
24
26
  terms.map! { |str| Regexp.escape(str) }
25
27
 
26
28
  @search = Regexp.new('(:?' + terms.join('|') + ')')
29
+ @buffer = String.new
27
30
  end
28
31
 
29
32
  def each
30
- buffer = String.new
31
-
32
33
  until @io.eof?
33
- buffer << @io.read(@max_read_size)
34
- each_segment(buffer) do |segment|
34
+ unpack(@io.read(@max_read_size)) do |segment|
35
35
  yield segment
36
36
  end
37
37
  end
38
38
  end
39
39
 
40
+ def unpack(str)
41
+ @buffer << str
42
+ each_segment(@buffer) do |segment|
43
+ yield segment
44
+ end
45
+ end
46
+
40
47
  def self.foreach(*args, &block)
41
48
  new(*args).each(&block)
42
49
  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.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Youch