Sha256: c2ce62805f6b99572e3c94f55e92decff0ef842d1ee20b1aa94485998b19f9f2
Contents?: true
Size: 1.61 KB
Versions: 1
Compression:
Stored size: 1.61 KB
Contents
require 'fileutils' require_relative 'provider_factory' class DataFileGenerator def initialize(config) @config = config @provider_factory = ProviderFactory.new end def generate provider = @provider_factory.create @config[:provider] requests = provider.get_requests @config.users_with_password, threads: @config[:threads] teams = @config[:teams].map do |team| { title: title(team), requests: team_requests(team, requests) } end requests.each { |r| replace_username_with_name r, :submitted_by, :assigned_to } FileUtils.mkdir_p output_dir teams.each { |t| create_data_file t } end private def title(team) team[:title] || "#{team[:name]} Help Desk Dashboard" end def team_requests(team, requests) members = team[:members].map { |m| username m } requests.select { |r| members.include? username(r[:submitted_by]) } end def replace_username_with_name(request, *keys) keys.each do |key| username = username(request[key]) user = get_user username request[key] = user[:name] if user end end def get_user(username) users_by_username[username][0] end def users_by_username @users_by_username ||= @config[:users].group_by { |u| username u[:username] } end def username(username) username.downcase end def create_data_file(team) File.write data_file_path(team), team.to_json end def data_file_path(team) file_name = "#{team[:team_name]}.json".downcase.gsub(' ', '-') File.join output_dir, file_name end def output_dir File.join @config[:output_dir], 'data' end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
help_desk_dashboard-0.0.6 | lib/help_desk_dashboard/lib/data_file_generator.rb |