Class: CsvMapper::FileHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/csv_mapper/file_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFileHandler

Returns a new instance of FileHandler.



5
6
7
# File 'lib/csv_mapper/file_handler.rb', line 5

def initialize()
  @path =  File.join(Rails.root.to_s, "tmp")
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



3
4
5
# File 'lib/csv_mapper/file_handler.rb', line 3

def filename
  @filename
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/csv_mapper/file_handler.rb', line 3

def path
  @path
end

Instance Method Details

#file_pathObject



24
25
26
# File 'lib/csv_mapper/file_handler.rb', line 24

def file_path
  File.join(@path, @filename)
end

#load_file(filename) ⇒ Object



15
16
17
18
# File 'lib/csv_mapper/file_handler.rb', line 15

def load_file(filename)
  @filename = filename
  File.exist?(file_path)
end

#remove_fileObject



20
21
22
# File 'lib/csv_mapper/file_handler.rb', line 20

def remove_file
  File.delete(file_path)
end

#save_temp_file(tempfile) ⇒ Object



9
10
11
12
13
# File 'lib/csv_mapper/file_handler.rb', line 9

def save_temp_file(tempfile)
  @filename = unique_filename
  FileUtils.copy_file(tempfile.path, file_path)
  File.exists?(file_path)
end

#unique_filenameObject



28
29
30
31
# File 'lib/csv_mapper/file_handler.rb', line 28

def unique_filename
  t = Time.now.strftime("%Y%m%d")
  "#{t}-#{$$}-#{rand(0x100000000000000).to_s(36)}"
end