Skip to content

Commit

Permalink
Don’t include an extensions list in Roo::Base#file_type_check, and on…
Browse files Browse the repository at this point in the history
…ly create the warning message if it is to be displayed.
  • Loading branch information
Empact committed Nov 22, 2014
1 parent 6d10403 commit 61eacd0
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/roo/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -508,24 +508,18 @@ def file_type_check(filename, ext, name, warning_level, packed=nil)
# getestet, falls es eine gepackte Datei ist.
filename = File.basename(filename,File.extname(filename))
end
case ext
when '.ods', '.xls', '.xlsx', '.csv', '.xml'
correct_class = "use #{Roo::CLASS_FOR_EXTENSION[ext]}.new to handle #{ext} spreadsheet files. This has #{File.extname(filename).downcase}"
else
raise "unknown file type: #{ext}"
end

if uri?(filename) && qs_begin = filename.rindex('?')
filename = filename[0..qs_begin-1]
end
if File.extname(filename).downcase != ext
case warning_level
when :error
warn correct_class
warn file_type_warning_message(filename, ext)
raise TypeError, "#{filename} is not #{name} file"
when :warning
warn "are you sure, this is #{name} spreadsheet file?"
warn correct_class
warn file_type_warning_message(filename, ext)
when :ignore
# ignore
else
Expand All @@ -550,6 +544,12 @@ def key_to_string(arr)

private

def file_type_warning_message(filename, ext)
"use #{Roo::CLASS_FOR_EXTENSION.fetch(ext)}.new to handle #{ext} spreadsheet files. This has #{File.extname(filename).downcase}"
rescue KeyError
raise "unknown file type: #{ext}"
end

def find_by_row(row_index)
row_index += (header_line - 1) if @header_line

Expand Down

0 comments on commit 61eacd0

Please sign in to comment.