Sha256: fc6c39f0bc96426799ca954a06c593014b44e31f0ef6326bbd9e44172bc0c6d8
Contents?: true
Size: 1.96 KB
Versions: 80
Compression:
Stored size: 1.96 KB
Contents
class Eco::API::UseCases::DefaultCases::SupersCyclicIdentify < Eco::API::Common::Loaders::UseCase name "identify-cyclic-supers" type :export attr_reader :session, :people, :options def main(people, session, options, usecase) options[:end_get] = false @session = session; @options = options; @people = people 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? session.logger.info("There were no cyclic supervisors identified!!") return end ext = File.extname(file).downcase.delete(".") File.open(file, "w") do |fd| if ext == "txt" create_file(data, file: file, format: :txt) elsif ext == "html" puts "html is still not supported" exit(1) create_file(data, file: file, format: :html) elsif ext == "json" puts "json is still not supported" exit(1) create_file(data, file: file, format: :json) end 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}#{(lev > 0)? "+-#{lev}- " : ""}#{entry.name} (#{entry.external_id}|#{entry.email}|#{entry.id})\n" str << set_to_str(set, lev: lev + 1, format: format) unless !set || set.empty? end end end
Version data entries
80 entries across 80 versions & 1 rubygems