Sha256: 14770faea0247f4b446937657675972386ec98f434e5991cd6c9cda1e1af635b

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

# Copyright:: (c) Autotelik Media Ltd 2011
# Author ::   Tom Statter
# Date ::     Aug 2010
# License::   MIT
#
#  Details::  Module for loaders, providing a process hook which populates a model,
#             based on a method map and supplied value from a file - i.e a single column/row's string value.
#             Note that although a single column, the string can be formatted to contain multiple values.
#
#             Tightly coupled with Binder classes (in lib/engine) which contains full details of
#             a file's column and it's correlated AR associations.
#
module DataShift

  module Loader

    class Factory

      # Based on file_name find appropriate Loader

      # Currently supports :
      #   Excel/Open Office files saved as .xls
      #   CSV files
      #
      def self.get_loader(file_name)

        raise DataShift::BadFile, "Cannot load #{file_name} file not found." unless File.exist?(file_name)

        ext = File.extname(file_name)

        if ext.casecmp('.xls') == 0 || ext.casecmp('.xlsx') == 0
          return ExcelLoader.new
        elsif ext.casecmp('.csv') == 0
          return CsvLoader.new
        else
          raise DataShift::UnsupportedFileType, "#{ext} files not supported - Try .csv or OpenOffice/Excel .xls"
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
datashift-0.40.3 lib/datashift/loaders/loader_factory.rb
datashift-0.40.1 lib/loaders/loader_factory.rb
datashift-0.40.0 lib/loaders/loader_factory.rb