Class: SpreadsheetManager

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

Overview

access to spreadsheets via roo

  • each file will only be opened once for all requests that are made

Instance Method Summary collapse

Constructor Details

#initializeSpreadsheetManager

Returns a new instance of SpreadsheetManager.



27
28
29
30
# File 'lib/spreadsheet_cache_manager_refi.rb', line 27

def initialize
	@ss_s = {} # file_pn => spreadsheet
	@metadata_s = {}
end

Instance Method Details

#get_metadata(ss_pn) ⇒ Object



49
50
51
52
53
54
# File 'lib/spreadsheet_cache_manager_refi.rb', line 49

def (ss_pn)
	if(@metadata_s[ss_pn] == nil)
		@metadata_s[ss_pn] = {"ss_pn" => ss_pn}.merge( File.(ss_pn) )
	end
	return @metadata_s[ss_pn]
end

#get_ss(ss_pn) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/spreadsheet_cache_manager_refi.rb', line 31

def get_ss(ss_pn)
	if @ss_s[ss_pn] == nil # spreadsheet not opened yet
		$Log.indent
		$Log.tlog( {id: 'info1035', ss_pn: ss_pn } )
		#dputi "K - open spreadsheet: #{$st[:ss_file]}#{ss_pn}"
		#myreq 'roo'
		file_extension = ss_pn.match(/.+\.(.+)$/)[1].to_s
		ss = case file_extension
			when 'xlsx' then Excelx.new(ss_pn)
			when 'xls' then Excel.new(ss_pn)
			when 'ods' then Openoffice.new(ss_pn)
		end
		@ss_s[ss_pn] = ss
		$Log.undent
		#dpun
	end
	return @ss_s[ss_pn]
end