Class: AsCSV::CSVBuilder
- Inherits:
-
Object
- Object
- AsCSV::CSVBuilder
- Defined in:
- lib/as_csv/csv_builder.rb
Instance Attribute Summary collapse
-
#csv_options ⇒ Object
readonly
Returns the value of attribute csv_options.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Instance Method Summary collapse
-
#initialize(records, options = {}) ⇒ CSVBuilder
constructor
A new instance of CSVBuilder.
- #to_csv ⇒ Object
Constructor Details
#initialize(records, options = {}) ⇒ CSVBuilder
Returns a new instance of CSVBuilder.
7 8 9 10 11 12 |
# File 'lib/as_csv/csv_builder.rb', line 7 def initialize(records, ={}) @records = Array(records) @options = @csv_options = .delete(:csv_options) || {} validate end |
Instance Attribute Details
#csv_options ⇒ Object (readonly)
Returns the value of attribute csv_options.
5 6 7 |
# File 'lib/as_csv/csv_builder.rb', line 5 def @csv_options end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/as_csv/csv_builder.rb', line 5 def @options end |
#records ⇒ Object (readonly)
Returns the value of attribute records.
5 6 7 |
# File 'lib/as_csv/csv_builder.rb', line 5 def records @records end |
Instance Method Details
#to_csv ⇒ Object
14 15 16 |
# File 'lib/as_csv/csv_builder.rb', line 14 def to_csv rows.collect { |row| CSV.generate_line row, }.join end |