Module: SeeAsVee::Helpers

Defined in:
lib/see_as_vee/helpers.rb

Class Method Summary collapse

Class Method Details

.file_with_type(whatever) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/see_as_vee/helpers.rb', line 5

def file_with_type whatever
  file =  case whatever
          when IO then whatever
          when String
            File.exist?(whatever) ? File.new(whatever) : Privates.tempfile(whatever)
          else
            raise SeeAsVee::Exceptions::BadInputError.new(whatever)
          end

  [
    file,
    (Privates.handler_name(FileMagic.new.file(file.path)) if Kernel.const_defined?('FileMagic')) ||
      Privates.handler_by_ext(file.path[/(?<=\.).*\z/])
  ].tap do |_, handle|
    raise SeeAsVee::Exceptions::FileFormatError.new(file.path) if handle.nil?
  end
end

.harvest_csv(whatever) ⇒ Object



24
25
26
27
# File 'lib/see_as_vee/helpers.rb', line 24

def harvest_csv whatever
  file, type = file_with_type whatever
  Privates.public_send("#{type}_to_array", file.path)
end