Sha256: 27babb399362c462191c3287d461e487afb2fc91ff6eff52523d6717608540c0

Contents?: true

Size: 649 Bytes

Versions: 1

Compression:

Stored size: 649 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(columns: nil)
      attributes = members
      attributes = columns & attributes if columns

      row = attributes.map do |column_name|
        column = public_send(column_name)
        next column.to_csv if column.respond_to?(:to_csv)
        next if column.nil?

        column.to_s
      end

      ::CSV.generate_line(row)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
honey_format-0.9.0 lib/honey_format/row_builder.rb