Sha256: 30a8f9b6d4e93ec89016a334880ed0b227109e0539a7e3aa006c11738666ef74

Contents?: true

Size: 744 Bytes

Versions: 1

Compression:

Stored size: 744 Bytes

Contents

# frozen_string_literal: true

require_relative 'acb/version'
require 'active_support'
require 'csv'

module Acb
  extend ActiveSupport::Concern

  autoload :Column, 'acb/column'
  autoload :Columns, 'acb/columns'

  class_methods do
    def columns
      @columns ||= Columns.new
    end

    def add_column(name:, **options)
      columns.push(name, **options)
    end
  end

  def data
    @data = @data.preload(relations) if respond_to?(:relations)
    @data.find_each
  end

  def get_data_from(row)
    self.class.columns.get_data(row)
  end

  def content_string(**options)
    CSV.generate(**options) do |csv|
      csv << self.class.columns.header
      data.each do |row|
        csv << get_data_from(row)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
acb-0.1.4 lib/acb.rb