Sha256: 2b3c732412e6079606d1d1ad76249da70d2a39c0f4dbf5d0d393eaf012900a0b
Contents?: true
Size: 1.9 KB
Versions: 19
Compression:
Stored size: 1.9 KB
Contents
class Eco::API::UseCases::Default::People::Treat::SupersCyclicIdentify < Eco::API::Common::Loaders::UseCase name "identify-cyclic-supers" type :export attr_reader :people def main(_people, _session, options, _usecase) options[:end_get] = false save!(cyclic_sets) end private def cyclic_sets Eco::API::Common::People::SupervisorHelpers.identify_cyclic_chains(people) end def file @file ||= options.dig(:output, :file) || "cyclic_supers.txt" end def save!(data) if data.empty? log(:info) { "There were no cyclic supervisors identified!!" } return end ext = File.extname(file).downcase.delete(".") case ext when "txt" create_file(data, file: file, format: :txt) when "html" log(:warn) { "html is still not supported" } exit(1) # create_file(data, file: file, format: :html) when "json" log(:warn) { "json is still not supported" } exit(1) # create_file(data, file: file, format: :json) end end def create_file(sets, file:, format: :txt) File.open(file, "w") do |fd| fd << sets_to_str(sets, format: format) end puts "Generated file #{file}" end def sets_to_str(sets, format: :txt) raise "Required Array. Given: #{sets.class}" unless sets.is_a?(Array) "".tap do |str| sets.each do |set| str << set_to_str(set, format: format) end end end def set_to_str(set, lev: 0, format: :txt) raise "Required Array. Given: #{set.class}" unless set.is_a?(Array) "".tap do |str| entry = set.shift str << (" " * lev) str << lev&.positive? ? "+-#{lev}- " : "" str << entry.name str << " (#{entry.external_id}|#{entry.email}|#{entry.id})\n" next unless set && !set.empty? str << set_to_str(set, lev: lev + 1, format: format) end end end
Version data entries
19 entries across 19 versions & 1 rubygems