Method: Crek::Book#initialize

Defined in:
lib/crek/book.rb

#initialize(path, options = {}) ⇒ Book

Returns a new instance of Book.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/crek/book.rb', line 17

def initialize path, options = {}
  check_file_extension = options.fetch(:check_file_extension, true)
  if check_file_extension
    extension = File.extname(options[:original_filename] || path).downcase
    raise 'Not a valid file format.' unless (['.xlsx', '.xlsm'].include? extension)
  end
  if options[:remote]
    zipfile = Tempfile.new("file")
    zipfile.binmode
    zipfile.write(HTTP.get(path).to_s)
    zipfile.close
    path = zipfile.path
  end
  @files = Zip::File.open path
  @shared_strings = SharedStrings.new(self)
end