class Arcana::Cursor
Attributes
buf[R]
offset[R]
Public Class Methods
new(buf)
click to toggle source
# File lib/arcana.rb, line 7 def initialize(buf) @buf = buf @base = @offset = 0 end
Public Instance Methods
eof?()
click to toggle source
# File lib/arcana.rb, line 12 def eof? @offset >= @buf.size end
inspect()
click to toggle source
# File lib/arcana.rb, line 54 def inspect "#<#{self.class} offset=#{@offset}>" end
mark_base()
click to toggle source
# File lib/arcana.rb, line 26 def mark_base @base += @offset @offset = 0 end
peek(n)
click to toggle source
# File lib/arcana.rb, line 22 def peek(n) @buf[@offset, n] end
read(n)
click to toggle source
# File lib/arcana.rb, line 16 def read(n) ret = peek(n) seek_relative(n) ret end
restore() { || ... }
click to toggle source
# File lib/arcana.rb, line 47 def restore prev = @offset, @base yield ensure @offset, @base = prev end
seek_absolute(offset)
click to toggle source
# File lib/arcana.rb, line 31 def seek_absolute(offset) if offset < 0 @offset = @buf.size + offset else @offset = offset end end
seek_pos(offset)
click to toggle source
# File lib/arcana.rb, line 39 def seek_pos(offset) seek_absolute(@base + offset) end
seek_relative(offset)
click to toggle source
# File lib/arcana.rb, line 43 def seek_relative(offset) @offset += offset end