class Xlsxtream::IO::Hash
Public Class Methods
new(stream)
click to toggle source
# File lib/xlsxtream/io/hash.rb, line 5 def initialize(stream) @stream = stream @hash = {} @path = nil end
Public Instance Methods
<<(data)
click to toggle source
# File lib/xlsxtream/io/hash.rb, line 11 def <<(data) @stream << data end
[](path)
click to toggle source
# File lib/xlsxtream/io/hash.rb, line 35 def [](path) fetch(path) rescue KeyError nil end
add_file(path)
click to toggle source
# File lib/xlsxtream/io/hash.rb, line 15 def add_file(path) close @path = path @hash[@path] = [@stream.tell] end
close()
click to toggle source
# File lib/xlsxtream/io/hash.rb, line 21 def close @hash[@path] << @stream.tell if @path end
fetch(path)
click to toggle source
# File lib/xlsxtream/io/hash.rb, line 25 def fetch(path) old = @stream.tell from, to = @hash.fetch(path) size = to - from @stream.seek(from) data = @stream.read(size) @stream.seek(old) data end
to_h()
click to toggle source
# File lib/xlsxtream/io/hash.rb, line 41 def to_h ::Hash[@hash.keys.map {|path| [path, fetch(path)] }] end