Class: Dossier::StreamCSV
- Inherits:
-
Object
- Object
- Dossier::StreamCSV
- Defined in:
- lib/dossier/stream_csv.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(collection, headers = nil) ⇒ StreamCSV
constructor
A new instance of StreamCSV.
Constructor Details
#initialize(collection, headers = nil) ⇒ StreamCSV
Returns a new instance of StreamCSV.
7 8 9 10 |
# File 'lib/dossier/stream_csv.rb', line 7 def initialize(collection, headers = nil) @headers = headers || collection.shift unless false === headers @collection = collection end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
5 6 7 |
# File 'lib/dossier/stream_csv.rb', line 5 def collection @collection end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
5 6 7 |
# File 'lib/dossier/stream_csv.rb', line 5 def headers @headers end |
Instance Method Details
#each ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dossier/stream_csv.rb', line 12 def each yield headers.to_csv if headers? collection.each do |record| yield record.to_csv end rescue => e if Rails.application.config.consider_all_requests_local yield e. e.backtrace.each do |line| yield "#{line}\n" end else yield "We're sorry, but something went wrong." end end |