binary_parser 1.2.1 → 1.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a266f80f4fbcd0daa0c318a5cfaa13d167eb96e4
4
- data.tar.gz: b8f1fe4f896e61d159ae5d4cdb010e01a0b6dc53
3
+ metadata.gz: 953f39760faff905b779f73aa1d40b43b63428d4
4
+ data.tar.gz: 30a7b07fb0e967f6e78ab6384faf57e83709a273
5
5
  SHA512:
6
- metadata.gz: fcecba5a4b014c53b276ce5422f894788429bb6124ae7acaf8a4e5043f5d253ecd26a919939afd8932ba67fde298340b8c15ad26f11fe89f8de57e7727143b9e
7
- data.tar.gz: de24b1e689b71dfdc407341ebb842d56ee8b819cc1c08c1ca0166a1c645bc6aa4f8ac3f77740dca8dea65611017e92914f7baaa9937910acd2c3c25d7aff5c34
6
+ metadata.gz: 5c5cae945b21dcb87450089f078b3e0a6d868de50666cf9aad5df05117b71176acf5d4dd8d5f389e83c18246c670d2f4c19bad85dd578847f0163c9d3ad2f9b6
7
+ data.tar.gz: 666b44776386e3c8af3c77dc83e7b12c8e21325d936f937ec48e10e27208fa2cb707a90b3a46b27dfb60b3253a94a6dfeb0217eb03dd4c27a7241266942b20c1
@@ -86,6 +86,22 @@ module BinaryParser
86
86
  return binary
87
87
  end
88
88
 
89
+ # Take n elements from stream. Behave like calling #get_next n times.
90
+ # Special cases:
91
+ # (1) If n elements do NOT exist in stream (only m elements exist),
92
+ # this method take m (< n) elements from stream.
93
+ def read(n)
94
+ res = []
95
+ n.times do
96
+ if rest?
97
+ res << get_next
98
+ else
99
+ break
100
+ end
101
+ end
102
+ return res
103
+ end
104
+
89
105
  # Remove elements until finding element which fullfils proc-condition or reaching end of stream.
90
106
  # return: array of removed elements
91
107
  #
@@ -148,6 +164,14 @@ module BinaryParser
148
164
  def rest?
149
165
  non_proceed_get_next
150
166
  end
167
+
168
+ def eof?
169
+ !rest?
170
+ end
171
+
172
+ def eof
173
+ eof?
174
+ end
151
175
 
152
176
  # Simply close binary-stream.
153
177
  def close
@@ -1,3 +1,3 @@
1
1
  module BinaryParser
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -69,6 +69,24 @@ module BinaryParser
69
69
  d4 = st.get_next
70
70
  assert_equal(nil, d4)
71
71
  end
72
+
73
+ def test_read
74
+ st = gen_stream(1, 2, 3,
75
+ 4, 5, 6,
76
+ 7, 8, 9)
77
+
78
+ ss = st.read(2)
79
+ assert_equal(2, ss.length)
80
+ assert_equal(1, ss[0].id.to_i)
81
+ assert_equal(4, ss[1].id.to_i)
82
+
83
+ ss = st.read(2)
84
+ assert_equal(1, ss.length)
85
+ assert_equal(7, ss[0].id.to_i)
86
+
87
+ ss = st.read(2)
88
+ assert_equal(0, ss.length)
89
+ end
72
90
 
73
91
  def test_seek_top_POPULAR_CASE
74
92
  st = gen_stream(1, 0, 0,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binary_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sawaken
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-16 00:00:00.000000000 Z
11
+ date: 2015-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler