Sha256: ebab6b7284b6713b723a9bf431d89154e5c0139b0e01629a142f028a2ea6c440

Contents?: true

Size: 791 Bytes

Versions: 2

Compression:

Stored size: 791 Bytes

Contents

module Spree
  class ReportGenerationService

    class << self
      delegate :reports, :report_exists?, :reports_for_category, :default_report_category, to: :configuration
      delegate :configuration, to: SolidusAdminInsights::Config
    end

    def self.generate_report(report_name, options)
      klass = Spree.const_get((report_name.to_s + '_report').classify)
      resource = klass.new(options)
      dataset = resource.generate
    end

    def self.download(report, options = {})
      headers = report.headers
      stats = report.observations
      ::CSV.generate(options) do |csv|
        csv << headers.map { |head| head[:name] }
        stats.each do |record|
          csv << headers.map { |head| record.public_send(head[:value]) }
        end
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
solidus_admin_insights-2.1.1 app/services/spree/report_generation_service.rb
solidus_admin_insights-2.1.0 app/services/spree/report_generation_service.rb