Skip to content

Instantly share code, notes, and snippets.

@falonofthetower
Created April 16, 2017 17:28
Show Gist options
  • Save falonofthetower/c2103cc072e33e364d450f6d52a86353 to your computer and use it in GitHub Desktop.
Save falonofthetower/c2103cc072e33e364d450f6d52a86353 to your computer and use it in GitHub Desktop.
require 'csv'
class User
attr_reader :user_lists_data, :ein, :name
def initialize(array)
@user_lists_data = array[0]
@ein = array[4]
end
end
class Termination
attr_reader :requestor, :term_string
def initialize(array)
@requestor = array[3]
@term_string = array[2].gsub(/Termed\ Associate\ \- /, '')
end
def ein
term_string.split("#").last
end
end
class List
attr_reader :name, :items
def initialize(name, items)
@name = name
@items = items
end
end
class FileReader
def self.process(path, processor)
raise ArgumentError if processor.nil?
csv = CSV.read path
name = File.basename path
items = csv.map { |list_item| processor.new list_item }
items.shift
List.new(name, items)
end
end
class Match
def initialize(terminations_path, *user_list_paths)
@terminations = create_terminations(terminations_path)
@user_lists = create_user_lists(user_list_paths)
master_list = []
@user_lists.each do |list|
this_list = {}
@terminations.items.each do |termination|
this_list[termination.term_string] = []
list.items.each do |user|
if user.ein.include?(termination.ein)
this_list[termination.term_string] << user.user_lists_data
end
end
end
master_list << List.new(list.name, this_list)
end
master_list.each do |list|
output.puts list.name
items = list.items.sort_by { |name, matches| matches }.reverse!
items.each do |termination, matches|
output.puts "#{matches.count} results for: #{termination}"
matches.each_with_index do |user, count|
output.puts " #{count + 1}: #{user}"
end
end
output.puts ""
end
end
def create_terminations(terminations_path)
FileReader.process(terminations_path, Termination)
end
def create_user_lists(user_list_paths)
user_lists = []
user_list_paths.each do |user_list_path|
user_lists << FileReader.process(user_list_path, User)
end
user_lists
end
def output
@output ||= File.new("output.txt", "w")
end
end
Match.new("2017-04-10 - Terms.xls - Sheet1.csv", "User Lists iSeries 170410.xlsx - AS400 RM BR CO 170410---NO PICK.csv", "User_List2.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment