Class: Npy::File

Inherits:
Object
  • Object
show all
Defined in:
lib/npy/file.rb

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ File

Returns a new instance of File.



3
4
5
6
7
8
9
10
11
12
# File 'lib/npy/file.rb', line 3

def initialize(io)
  @streams = {}
  Zip::File.open_buffer(io) do |zipfile|
    zipfile.each do |entry|
      name = entry.name.sub(/\.npy\z/, "")
      @streams[name] = entry.get_input_stream
    end
  end
  @data = {}
end

Instance Method Details

#[](name) ⇒ Object



18
19
20
# File 'lib/npy/file.rb', line 18

def [](name)
  @data[name] ||= Npy.load_io(@streams[name]) if @streams[name]
end

#keysObject



14
15
16
# File 'lib/npy/file.rb', line 14

def keys
  @streams.keys
end

#to_hObject



22
23
24
# File 'lib/npy/file.rb', line 22

def to_h
  keys.map { |k| [k, self[k]] }.to_h
end