Class: Eco::API::UseCases::Default::Utils::GroupCsv::FileHandler
- Defined in:
- lib/eco/api/usecases/default/utils/group_csv_case/file_handler.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
Instance Method Summary collapse
- #<<(value) ⇒ Object
- #close ⇒ Object
-
#initialize(filename, format: :csv) ⇒ FileHandler
constructor
A new instance of FileHandler.
Constructor Details
#initialize(filename, format: :csv) ⇒ FileHandler
Returns a new instance of FileHandler.
5 6 7 8 9 10 |
# File 'lib/eco/api/usecases/default/utils/group_csv_case/file_handler.rb', line 5 def initialize(filename, format: :csv) @filename = filename @format = format open end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
3 4 5 |
# File 'lib/eco/api/usecases/default/utils/group_csv_case/file_handler.rb', line 3 def filename @filename end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
3 4 5 |
# File 'lib/eco/api/usecases/default/utils/group_csv_case/file_handler.rb', line 3 def format @format end |
Instance Method Details
#<<(value) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/eco/api/usecases/default/utils/group_csv_case/file_handler.rb', line 12 def <<(value) msg = "File has been closed. Can't write to it: #{filename}" raise msg unless file case format when :csv file << value when :jsonl file.puts to_s(value) end end |
#close ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/eco/api/usecases/default/utils/group_csv_case/file_handler.rb', line 24 def close return if file.nil? file.close.tap do @file = nil end end |