Class: Scruber::Core::Extensions::CsvOutput
- Inherits:
-
Base
show all
- Defined in:
- lib/scruber/core/extensions/csv_output.rb
Overview
Helper to write csv files
Defined Under Namespace
Modules: CoreMethods
Class Method Summary
collapse
Methods inherited from Base
descendants, inherited, register
Class Method Details
._registered_files ⇒ Object
70
71
72
|
# File 'lib/scruber/core/extensions/csv_output.rb', line 70
def _registered_files
@registered_files ||= {}
end
|
.close_all ⇒ Object
74
75
76
77
|
# File 'lib/scruber/core/extensions/csv_output.rb', line 74
def close_all
_registered_files.each{ |_,f| f.close }
@registered_files = {}
end
|
.csv_out(file_id, fields) ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/scruber/core/extensions/csv_output.rb', line 56
def csv_out(file_id, fields)
if _registered_files.keys.include?(file_id.to_sym)
_registered_files[file_id.to_sym] << fields
else
raise ArgumentError, "file #{file_id.inspect} not registered"
end
end
|
.register_csv(file_id, path, options) ⇒ Object
64
65
66
67
68
|
# File 'lib/scruber/core/extensions/csv_output.rb', line 64
def register_csv(file_id, path, options)
mode = options.fetch(:mode){ 'wb' }
options.delete(:mode)
_registered_files[file_id] = CSV.open(path, mode, options)
end
|