Sha256: 057ed29566a407a7cf962f1e004cefc288835709af7c20b027441938c260a962

Contents?: true

Size: 765 Bytes

Versions: 3

Compression:

Stored size: 765 Bytes

Contents

require 'honey_format/row'

module HoneyFormat
  # Represents rows.
  class Rows
    # Returns array of cleaned strings.
    # @return [Rows] new instance of Rows.
    # @param [Array] rows the array of rows.
    # @param [Array] columns the array of column symbols.
    def initialize(rows, columns)
      @rows = prepare_rows(Row.new(columns), rows)
    end

    # Returns rows as array.
    # @return [Array] of rows.
    def to_a
      @rows
    end

    private

    def prepare_rows(builder, rows)
      built_rows = []
      rows.each do |row|
        unless row.first.nil? # The Ruby CSV library returns empty lines as [nil], ignore them..
          built_rows << builder.build(Sanitize.array!(row))
        end
      end
      built_rows
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
honey_format-0.3.0 lib/honey_format/rows.rb
honey_format-0.2.1 lib/honey_format/rows.rb
honey_format-0.2.0 lib/honey_format/rows.rb