class Object

Public Instance Methods

com_separated_files(output) click to toggle source
# File lib/prune-erickson.rb, line 115
def com_separated_files (output)
        # puts output
        com_data = {
                'com_codes' => ['apl', 'ach', 'bbv', 'ccv', 'cci', 'cwf', 'dvf', 'eth', 'frv', 'gsv', 'hsd', 'lhn', 'lph', 'mgc', 'ocv', 'rwv', 'sbv', 'tck', 'wcd'],
                'labels' => Array.new,
        }
        com_data['com_codes'].each do |code|
                com_data[code] = Array.new
        end
        original = Spreadsheet.open(output)
        original_sheet = original.worksheet(0)
        
        rowlength = original_sheet.row(0)
        # puts rowlength.length
        # make a directory for the new files
        unless File.directory?("com_separated_files")
                %x(mkdir com_separated_files)
        end
        original_sheet.each do |row|
                com_data['com_codes'].each do |code|
                        if row[0] == "#{code}".upcase
                        # print row to other array and print label to a community array
                                row.each do |x|
                                        com_data[code].push x
                                end
                                unless com_data['labels'].include?("#{code}".upcase)
                                        com_data['labels'].push "#{code}".upcase
                                end
                        end
                end
        end
        print "creating files for these communities:\n".blue
        puts "#{com_data['labels']}".blue
        puts "you can see your files in this directory"
        puts "../com_separated_files"
        com_data['com_codes'].each do |code|
                if com_data[code].length > 0
                        printFile(com_data[code], rowlength, "com_separated_files/#{code}.xls", "", 0, 0,1,1)
                end
        end
end
fieldChecker(row,fields) click to toggle source

new_fields = [‘Community of Interest’,‘First Name’,‘Last Name’,‘Address 1’,‘city’,‘State or Province’,‘Zip or Postal Code’,‘Email Address’,‘Home Phone’]

# File lib/prune-erickson.rb, line 26
def fieldChecker (row,fields)
        
        fields.each do |field|
                unless row.include? field     
                        print "you are missing the #{field} field\n".yellow.blink
                else
                end
        end
end
labelChecker(row, testvar) click to toggle source

FUNCTIONS


# File lib/prune-erickson.rb, line 15
def labelChecker (row, testvar)

        row.each_with_index{|val, index| 

                unless val != "OppCommunity" and val !="FirstName" and val != "LastName" and val != "Address" and val!="City" and val != "State" and val != "Zipcode" and val != "Phone" and val != "Email" and val != "ILorCC"
                        testvar.push(index)
                end
        }
end
printFile(newvar, testvar, output, il_or_cc, k=0, l=1,offset=0, j_int_offset = 0) click to toggle source
# File lib/prune-erickson.rb, line 84
def printFile (newvar, testvar, output, il_or_cc, k=0, l=1,offset=0, j_int_offset = 0)
        
        newBook = Spreadsheet::Workbook.new
        newSheet = newBook.create_worksheet
        if il_or_cc == ""
                testvar.each do |x|
                        newSheet.row(0).push x
                end
        end
        for i in k..newvar.length
        
                for j in l..(testvar.length-j_int_offset)     
                                newSheet.row(i+offset).push newvar[(i*testvar.length)+j]
                end
                if il_or_cc != ""
                        if i > 0
                                newSheet.row(i).push "#{il_or_cc}"

                        else
                                newSheet.row(i).push "ILorCC"
                        end
                end
        end
        if il_or_cc == ""
                puts "   |--> #{output[20..26]}" 
        else
                puts "output file is in same file under out.xls to open, use \n \n open #{output}"
        end
        newBook.write output
end
processData(sheet, newvar, testvar) click to toggle source
# File lib/prune-erickson.rb, line 36
def processData (sheet, newvar, testvar)
        
        newvar.push "zero"
        sheet.each do |row|
                row.each_with_index {|val, index| 
                        if testvar.include? index
                                
                                newvar.push val
                        end
                }
        end
        print "~~>writing new file \n\n"
        
        newvar.map! { |x| 

                if x == "OppCommunity"
                        print "renaming field #{x} \n".colorize(:light_blue)
                        x = "Community of Interest"
                elsif x == "FirstName"
                        print "renaming field #{x} \n".colorize(:light_blue)
                        x = "First Name"     
                elsif x == "LastName"
                        print "renaming field #{x} \n".colorize(:light_blue)
                        x = "Last Name"
                elsif x == "Address"
                        print "renaming field #{x} \n".colorize(:light_blue)
                        x = "Address 1"
                elsif x == "city"
                        print "renaming field #{x} \n".colorize(:light_blue)
                        x = "city"
                elsif x == "State"
                        print "renaming field #{x} \n".colorize(:light_blue)
                        x = "State or Province"
                elsif x == "Zipcode"
                        print "renaming field #{x} \n".colorize(:light_blue)
                        x = "Zip or Postal Code"
                elsif x == "Email"
                        print "renaming field #{x} \n".colorize(:light_blue)
                        x = "Email Address"
                elsif x == "Phone"
                        print "renaming field #{x} \n".colorize(:light_blue)
                        x = "Home Phone"
                else
                        x=x
                end
        }
end