Class: SheetData
Constant Summary collapse
- @@log =
init_logger(STDOUT, Logger::INFO)
- @@file =
nil
- @@workbook =
nil
Class Method Summary collapse
Methods included from Logging
init_logger, log_level=, log_target=
Methods included from File_Checking
Class Method Details
.workbook(file) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/sheetdata.rb', line 48 def self::workbook(file) @@file = file if !@@workbook begin magic, mime = file_type @@workbook = case mime when ODS_MIME if magic.match ODS_Magic @@log.debug('ODS') Roo::Spreadsheet::open(@@file, extension: :ods ) end when XLS_MIME if magic.match XLS_Magic @@log.debug('XLS') Roo::Spreadsheet::open(@@file, extension: :xls ) end when XLSX_MIME if magic.match XLSX_Magic @@log.debug('XLSX') Roo::Spreadsheet::open(@@file, extension: :xlsx ) end when CSV_MIME raise IOError.new('CSV is not yet supported, sorry') else raise IOError.new('Mime-Type is ' << mime << ' and Magic sais: ' << magic << ". Is this supposed to be a spreadsheet?") end rescue Exception => ex msg = 'ERROR! File %s is not supported: %s' %[@@file, ex.] puts msg @log.error yellow(msg) exit false end return @@workbook end end |