lib/csv_shaper/encoder.rb in csv_shaper-0.0.3 vs lib/csv_shaper/encoder.rb in csv_shaper-0.1.0
- old
+ new
@@ -1,8 +1,14 @@
require 'csv'
module CsvShaper
+ # Encoder
+ # Takes a Header and Array of Rows and converts them to a valid CSV formatted String
+ # Example:
+ # ```
+ # CsvShaper::Encoder.new(@header, @rows).to_csv
+ # ```
class Encoder
def initialize(header, rows = [])
if header.nil?
raise MissingHeadersError, 'you must define some headers using csv.headers ...'
end
@@ -24,10 +30,10 @@
table.to_csv
end
private
- # Internal: make use of CSV#values_at to pad out the
+ # Internal: make use of `CSV#values_at` to pad out the
# cells into the correct columns for the headers
#
# Returns an Array of Arrays
def padded_rows
rows = @rows.map do |row|