Class: Csv
Instance Attribute Summary collapse
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Class Method Summary collapse
-
.parse(data, args = {}) ⇒ Object
Public: Parses raw CSV data into a usable format.
Instance Method Summary collapse
-
#to_s ⇒ Object
Public: Converts the instance to a raw CSV string.
Instance Attribute Details
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
4 5 6 |
# File 'lib/helpers/tmc_helpers/csv_helper/csv_helper.rb', line 4 def rows @rows end |
Class Method Details
.parse(data, args = {}) ⇒ Object
Public: Parses raw CSV data into a usable format.
data - String data to parse. header - Boolean indicating whether the data contains a header row (default: false).
Returns a Csv instance.
12 13 14 |
# File 'lib/helpers/tmc_helpers/csv_helper/csv_helper.rb', line 12 def self.parse(data, args={}) Csv.new(data, args) end |
Instance Method Details
#to_s ⇒ Object
Public: Converts the instance to a raw CSV string.
Returns a String of CSV data.
19 20 21 22 23 |
# File 'lib/helpers/tmc_helpers/csv_helper/csv_helper.rb', line 19 def to_s rows = @header.nil? ? [] : [@header] rows += @rows.map {|obj| obj.values} rows.map {|row| row.join(',')}.join("\n") end |