Sha256: e1e9fb1b42800039266da619fd6c6bc5e3bedf5b417afceb5778d73085c93971

Contents?: true

Size: 689 Bytes

Versions: 1

Compression:

Stored size: 689 Bytes

Contents

module AWS
  module S3
    # Methods extending the S3Object class provided by the aws-s3 gem.
    class S3Object
      alias_method :name, :key

      # Returns the class represented by the csv file.
      #  person.csv => Person
      def to_class_name
        self.key.gsub('.csv','').split('_').map { |word| word.capitalize}.join
      end

      # Copies the S3 Object to a local directory.
      #   save_to('tmp/file.csv')
      #   Copied files are in ISO-8859-1 encoding
      def save_to(path)
        File.open(path,'wb') do |file|
          S3Object.stream(self.key,self.bucket.name) do |chunk|
            file.write chunk
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
redis_importer-1.1.7 lib/extensions/s3.rb