Skip to content

Instantly share code, notes, and snippets.

@andyh
Forked from anonymous/SpreadsheetTagService.rb
Last active December 20, 2015 12:19
Show Gist options
  • Save andyh/6130659 to your computer and use it in GitHub Desktop.
Save andyh/6130659 to your computer and use it in GitHub Desktop.
class SpreadsheetTagService
include Roo
def initialize(uploaded_file)
@spreadsheet = open_spreadsheet(uploaded_file)
do_stuff
end
private
def do_stuff
# assuming that all the different classes have the same interface you're planning to use
@spreadsheet.each_with_pagename do |name,sheet|
Rails.logger.debug( sheet )
end
end
def open_spreadsheet(file)
case File.extname(file.path)
when ".csv" then Csv.new(file.path, nil, :ignore)
when ".xls" then Excel.new(file.path, nil, :ignore)
when ".xlsx" then Excelx.new(file.path, nil, :ignore)
else raise "Unknown file type: #{file.original_filename}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment