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.
- checksums.yaml +4 -4
- data/lib/io-segmenter.rb +11 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41882b615cb02ee0e614e868104006e98fafb0ba0b96adb0d55431b13d285116
|
4
|
+
data.tar.gz: 86655c3225adc2bb178d3a31cb4b4cd37f37d538b419316eddd56e24b3059f1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|