Class: Aerospike::Utils::StringParser
- Inherits:
-
Object
- Object
- Aerospike::Utils::StringParser
- Defined in:
- lib/aerospike/utils/string_parser.rb
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Instance Method Summary collapse
- #current ⇒ Object
-
#expect(char) ⇒ Object
Reads next character and raise if not matching desired one.
-
#initialize(str) ⇒ StringParser
constructor
A new instance of StringParser.
- #read_until(char) ⇒ Object
- #step(count = 1) ⇒ Object
Constructor Details
#initialize(str) ⇒ StringParser
Returns a new instance of StringParser.
24 25 26 |
# File 'lib/aerospike/utils/string_parser.rb', line 24 def initialize(str) @io = ::StringIO.new(str) end |
Instance Attribute Details
#io ⇒ Object (readonly)
Returns the value of attribute io.
23 24 25 |
# File 'lib/aerospike/utils/string_parser.rb', line 23 def io @io end |
Instance Method Details
#current ⇒ Object
28 29 30 |
# File 'lib/aerospike/utils/string_parser.rb', line 28 def current @io.string[@io.tell] end |
#expect(char) ⇒ Object
Reads next character and raise if not matching desired one
33 34 35 |
# File 'lib/aerospike/utils/string_parser.rb', line 33 def expect(char) raise ::Aerospike::Exceptions::Parse unless @io.read(1) == char end |
#read_until(char) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/aerospike/utils/string_parser.rb', line 37 def read_until(char) [].tap do |result| loop do chr = @io.read(1) break if chr == char result << chr end end.join end |
#step(count = 1) ⇒ Object
47 48 49 |
# File 'lib/aerospike/utils/string_parser.rb', line 47 def step(count = 1) @io.read(count) end |