class Processor
class containing the functionalities of handling the whole show¶ ↑
Attributes
unmatched[R]
Public Class Methods
new(opts)
click to toggle source
# File lib/mylookup/processor.rb, line 9 def initialize(opts) @l_db, @l_tbl, @l_on = opts[:left], opts[:leftsheet], opts[:lefton] @r_db, @r_tbl, @r_on = opts[:right], opts[:rightsheet], opts[:righton] @verbose = opts[:verbose] @l_src, @r_src = opts[:l_src], opts[:r_src] @l_reader, @r_reader = nil, nil @l_data, @r_data, @matched, @unmatched = nil, nil, nil, nil if @l_src == :excel @l_reader = FileReader::Excel.new(@l_db, @l_tbl, @l_on) else @l_reader = FileReader::MongoDB.new(@l_on, @l_tbl, db_name: @l_db) end if @r_src == :excel @r_reader = FileReader::Excel.new(@r_db, @r_tbl, @r_on) else @r_reader = FileReader::MongoDB.new(@r_on, @r_tbl, db_name: @r_db) end end
Public Instance Methods
process()
click to toggle source
Executes reading, lookup and writing the unmatched
# File lib/mylookup/processor.rb, line 29 def process puts "Processing initiating..." read_data mylookup write_unmatched unless @unmatched.empty? end
process_without_writing()
click to toggle source
Processes [Reading and Lookup] without writing the unmatched
# File lib/mylookup/processor.rb, line 37 def process_without_writing puts "Processing initiating..." read_data mylookup end
Private Instance Methods
mylookup()
click to toggle source
Filters out the unmatched data
# File lib/mylookup/processor.rb, line 44 def mylookup puts "Executing mylookup..." @unmatched = @l_data - @r_data @matched = @l_data - @unmatched puts "[Info]: Left Table size: #{@l_data.size} row(s)" puts "Matched: #{@matched.size} row(s) Unmatched: #{@unmatched.size} row(s)" puts "Matched: #{(@matched.size.to_f*100/@l_data.size.to_f).round(2)}%" end
read_data()
click to toggle source
Reads the Source data
# File lib/mylookup/processor.rb, line 60 def read_data puts "Reading Left Table data..." l_comment = @l_reader.read @l_data = @l_reader.data puts "Reading Right Table data..." r_comment = @r_reader.read @r_data = @r_reader.data puts "[Info]: LEFT =>#{l_comment}" puts "[Info]: RIGHT=>#{r_comment}" end
write_unmatched()
click to toggle source
Writes the unmatched data
# File lib/mylookup/processor.rb, line 54 def write_unmatched writer = FileWriter::Excel.new('unmatched.xlsx', @unmatched, @l_on) writer.write end