Class: Box::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/box/reader.rb

Instance Method Summary collapse

Constructor Details

#initializeReader

Returns a new instance of Reader.



5
6
7
# File 'lib/box/reader.rb', line 5

def initialize
	@data = Hash.new
end

Instance Method Details

#load(data) ⇒ Object



18
19
20
21
22
23
# File 'lib/box/reader.rb', line 18

def load(data)
	json = JSON.load(data)
	@data = unpack_data( json )

	return @data
end

#read(path) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/box/reader.rb', line 25

def read(path)
	fp = File.new(path, "r")
	data = fp.read
	fp.close

	load data
end

#unpack_data(data) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/box/reader.rb', line 9

def unpack_data(data)
	unpacked = Hash.new

	data.each do |k,v|
		unpacked[k] = Packer.unpack(v)
	end

	return unpacked
end