Class: CsvStream
- Inherits:
-
Object
- Object
- CsvStream
- Defined in:
- lib/csv_uploader_tool/csv_stream.rb
Constant Summary collapse
- BUFFER_SIZE =
1024
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(file) ⇒ CsvStream
constructor
A new instance of CsvStream.
- #write(stream) ⇒ Object
Constructor Details
#initialize(file) ⇒ CsvStream
Returns a new instance of CsvStream.
5 6 7 |
# File 'lib/csv_uploader_tool/csv_stream.rb', line 5 def initialize(file) @file = file end |
Class Method Details
.fetch(dir) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/csv_uploader_tool/csv_stream.rb', line 18 def fetch(dir) all_files = Dir[dir+'/*'].select {|x| x =~ /_.*(csv)/ } actual_names = [] all_files.each do |path| actual_names << File.basename(path) end actual_names end |
.write(stream, dir, filename) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/csv_uploader_tool/csv_stream.rb', line 10 def write(stream, dir, filename) file = CsvMaker.create_file(dir, filename) file_stream = CsvStream.new(file) file_stream.write stream file_stream.close file.path end |
Instance Method Details
#close ⇒ Object
34 35 36 |
# File 'lib/csv_uploader_tool/csv_stream.rb', line 34 def close @file.close unless @file.closed? end |
#write(stream) ⇒ Object
28 29 30 31 32 |
# File 'lib/csv_uploader_tool/csv_stream.rb', line 28 def write(stream) while(bytes = stream.read(BUFFER_SIZE)) @file.write bytes end end |