Sha256: 619d6e7fb8e69427a40fb1b78e7aef396c579e9bea245af569f49cc4290b4a50

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

require 'fileutils'
require_relative 'app_config'
require_relative 'provider_factory'

class DataFileGenerator

  def initialize(config, output_dir)
    @config = config
    @output_dir = output_dir
  end

  def generate
    provider_factory = ProviderFactory.new
    provider = provider_factory.create @config[:provider]
    requests = provider.get_requests @config.users_with_password, threads: @config[:threads]
    requests_by_submitter = requests.group_by { |r| r[:submitted_by] }
    teams = @config[:teams].map do |team|
      {
          team_name: team[:name],
          title: "#{team[:name]} Help Desk Requests",
          requests: team[:members].map { |username| requests_by_submitter[username] }.flatten.compact
      }
    end

    requests.each do |r|
      user = config[:users].find { |u| u[:username] == r[:assigned_to] }
      r[:assigned_to] = user[:name] if user
      user = config[:users].find { |u| u[:username] == r[:submitted_by] }
      r[:submitted_by] = user[:name] if user
    end

    FileUtils.rm_rf @output_dir
    FileUtils.mkdir_p @output_dir
    teams.each { |t| create_data_file t }

  end

  private

  def create_data_file(team)
    file_name = "#{team[:team_name]}.json".downcase.gsub(' ', '-')
    path = File.join @output_dir, file_name
    File.write path, team.to_json
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
help_desk_dashboard-0.0.5 lib/help_desk_dashboard/lib/data_file_generator.rb