Sha256: 9e3789c6f04307aa6a4b49e8430e181410d157facbc3de16b33533fea61b3514

Contents?: true

Size: 535 Bytes

Versions: 2

Compression:

Stored size: 535 Bytes

Contents

module HoneyFormat
  # Default row builder
  class RowBuilder < Struct
    # Create a row
    # @return [Struct] returns an instantiated Struct representing a row
    def self.call(row)
      new(*row)
    end

    # Represent row as CSV
    # @return [String] CSV-string representation.
    def to_csv
      members.map do |column_name|
        column = public_send(column_name)
        if column.respond_to?(:to_csv)
          column.to_csv
        else
          column.to_s
        end
      end.join(',') + "\n"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
honey_format-0.8.0 lib/honey_format/row_builder.rb
honey_format-0.7.0 lib/honey_format/row_builder.rb