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.
- #prev ⇒ Object
- #read_until(*args) ⇒ Object
- #step(count = 1) ⇒ Object
Constructor Details
#initialize(str) ⇒ StringParser
Returns a new instance of StringParser.
25 26 27 |
# File 'lib/aerospike/utils/string_parser.rb', line 25 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
29 30 31 |
# File 'lib/aerospike/utils/string_parser.rb', line 29 def current @io.string[@io.tell] end |
#expect(char) ⇒ Object
Reads next character and raise if not matching desired one
34 35 36 |
# File 'lib/aerospike/utils/string_parser.rb', line 34 def expect(char) raise ::Aerospike::Exceptions::Parse unless @io.read(1) == char end |
#prev ⇒ Object
48 49 50 |
# File 'lib/aerospike/utils/string_parser.rb', line 48 def prev @io.string[@io.tell - 1] end |
#read_until(*args) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/aerospike/utils/string_parser.rb', line 38 def read_until(*args) [].tap do |result| loop do chr = @io.read(1) break if args.include?(chr) result << chr end end.join end |
#step(count = 1) ⇒ Object
52 53 54 |
# File 'lib/aerospike/utils/string_parser.rb', line 52 def step(count = 1) @io.read(count) end |