prune-erickson 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/prune-erickson +156 -0
  3. data/lib/prune-erickson.rb +160 -0
  4. metadata +66 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5ad24e0c8ae32742867cd7ad50e7a5f6f5b60cb4
4
+ data.tar.gz: 9e5430163719fde2abba0485e4ebee6a536e5b78
5
+ SHA512:
6
+ metadata.gz: 4e410baf56dbf18dc48eedaf55c6cadbea754716a35582646031ef1afe3ba6a59c73c9928977373b30a6e0bb26562478cb7d55e9931a027bd3a83f0e88363613
7
+ data.tar.gz: 02559482a9b72fa6a072a6bafeff91304cffaa411629fab2cec7e6fc09a9e3b968e3ccc1a8ff1ee4aeace5162c88124620f66c121618dab2d2ab83c98908216c
@@ -0,0 +1,156 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'spreadsheet'
4
+
5
+
6
+ # --------------------------------------------
7
+ # GRABS INFORMATION FROM COMMAND LINE AND MAKES DATA AVAILABLE FOR PROGRAM
8
+ fileName = ARGV[0]
9
+ sheetNum = ARGV[1].to_i-1
10
+ output = ARGV[2]
11
+ if sheetNum > 0
12
+ print fileName
13
+ print "\n"
14
+
15
+ print sheetNum
16
+ end
17
+ print "\n\n"
18
+ # --------------------------------------------
19
+ # ASKING FOR HELP
20
+ if ARGV.length == 1 and ARGV[0] == "help"
21
+ print "
22
+ THANK YOU FOR USING PRUNE!! /_(O__O)_/
23
+ \n
24
+ .. ...
25
+ | | / /
26
+ | | / /
27
+ | | / /
28
+ | |/ ;-._
29
+ } ` _/ / ;
30
+ | /` ) / /
31
+ | / /_/_ /| \s
32
+ |/ / |
33
+ ( ' \ '- |
34
+ \ `. /
35
+ | |
36
+ | | \n\n\n
37
+ to edit a file use this format:
38
+
39
+ prune-erickson [filename.xls (string)] [sheet-number (number)] [output.xls (string)]\n\n\n\n
40
+ "
41
+ else
42
+ # --------------------------------------------
43
+ Spreadsheet.client_encoding = 'UTF-8'
44
+ print "~>reading file you have requested"
45
+ print "\n"
46
+ # reads file
47
+ book = Spreadsheet.open fileName
48
+ sheet1 = book.worksheet sheetNum
49
+
50
+ print '\n'
51
+ newBook = Spreadsheet::Workbook.new
52
+ newSheet = newBook.create_worksheet
53
+
54
+ newSheet.name = "output"
55
+
56
+ testvar = Array.new
57
+
58
+ print "~>looking for unnecessary information"
59
+ print "\n"
60
+ sheet1.row(0).each_with_index{|val, index|
61
+
62
+ 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"
63
+ testvar.push(index)
64
+ end
65
+ }
66
+
67
+ unless sheet1.row(0).include? "OppCommunity"
68
+ print "you are missing the OppCommunity field\n".upcase
69
+ else
70
+
71
+ end
72
+ unless sheet1.row(0).include? "FirstName"
73
+ print "you are missing the FirstName field\n".upcase
74
+ end
75
+ unless sheet1.row(0).include? "LastName"
76
+ print "you are missing the LastName field\n".upcase
77
+ end
78
+ unless sheet1.row(0).include? "Phone"
79
+ print "you are missing the phone field\n".upcase
80
+ end
81
+ unless sheet1.row(0).include? "Address"
82
+ print "you are missing the Address field\n".upcase
83
+ end
84
+ unless sheet1.row(0).include? "City"
85
+ print "you are missing the City field\n".upcase
86
+ end
87
+ unless sheet1.row(0).include? "State"
88
+ print "you are missing the State field\n".upcase
89
+ end
90
+ unless sheet1.row(0).include? "Zipcode"
91
+ print "you are missing the Zipcode field\n".upcase
92
+ end
93
+ unless sheet1.row(0).include? "Address"
94
+ print "you are missing the Address field\n".upcase
95
+ end
96
+ unless sheet1.row(0).include? "Address"
97
+ print "you are missing the Address field\n".upcase
98
+ end
99
+ unless sheet1.row(0).include? "Email"
100
+ print "you are missing the Email field\n".upcase
101
+ end
102
+ # puts testvar
103
+ newvar = Array.new
104
+ newvar.push "zero"
105
+ sheet1.each do |row|
106
+ row.each_with_index {|val, index|
107
+ if testvar.include? index
108
+
109
+ newvar.push val
110
+ end
111
+ }
112
+ end
113
+ print "~~>writing new file \n\n"
114
+ # print newvar
115
+ newvar.map! { |x|
116
+
117
+ if x == "OppCommunity"
118
+ print "renaming field #{x} \n"
119
+ x = "Community"
120
+ elsif x == "FirstName"
121
+ print "renaming field #{x} \n"
122
+ x = "First Name"
123
+ elsif x == "LastName"
124
+ print "renaming field #{x} \n"
125
+ x = "Last Name"
126
+ elsif x == "Address"
127
+ print "renaming field #{x} \n"
128
+ x = "Address"
129
+ elsif x == "city"
130
+ print "renaming field #{x} \n"
131
+ x = "city"
132
+ elsif x == "State"
133
+ print "renaming field #{x} \n"
134
+ x = "State"
135
+ elsif x == "Zipcode"
136
+ print "renaming field #{x} \n"
137
+ x = "Zipcode"
138
+ elsif x == "Email"
139
+ print "renaming field #{x} \n"
140
+ x = "Email"
141
+ else
142
+ x=x
143
+ end
144
+ }
145
+ # print newvar
146
+ for i in 0..newvar.length
147
+ for j in 1..testvar.length
148
+
149
+
150
+ newSheet.row(i).push newvar[(i*testvar.length)+j]
151
+ end
152
+ end
153
+ print "output file is in same file under out.xls to open, use \n \n open #{output}"
154
+ print "\n"
155
+ newBook.write output
156
+ end
@@ -0,0 +1,160 @@
1
+ require 'spreadsheet'
2
+
3
+
4
+ class Prune
5
+ def self.run(fileName,sheetNum,output)
6
+
7
+
8
+ # --------------------------------------------
9
+ # GRABS INFORMATION FROM COMMAND LINE AND MAKES DATA AVAILABLE FOR PROGRAM
10
+ # fileName = ARGV[0]
11
+ # sheetNum = ARGV[1].to_i-1
12
+ # output = ARGV[2]
13
+ if sheetNum > 0
14
+ print fileName
15
+ print "\n"
16
+
17
+ print sheetNum
18
+ end
19
+ print "\n\n"
20
+ # --------------------------------------------
21
+ # ASKING FOR HELP
22
+ if ARGV.length == 1 and ARGV[0] == "help"
23
+ print "
24
+ THANK YOU FOR USING PRUNE!! /_(O__O)_/
25
+ \n
26
+ .. ...
27
+ | | / /
28
+ | | / /
29
+ | | / /
30
+ | |/ ;-._
31
+ } ` _/ / ;
32
+ | /` ) / /
33
+ | / /_/_ /| \s
34
+ |/ / |
35
+ ( ' \ '- |
36
+ \ `. /
37
+ | |
38
+ | | \n\n\n
39
+ to edit a file use this format:
40
+
41
+ prune-erickson [filename.xls (string)] [sheet-number (number)] [output.xls (string)]\n\n\n\n
42
+ "
43
+ else
44
+ # --------------------------------------------
45
+ Spreadsheet.client_encoding = 'UTF-8'
46
+ print "~>reading file you have requested"
47
+ print "\n"
48
+ # reads file
49
+ book = Spreadsheet.open fileName
50
+ sheet1 = book.worksheet sheetNum
51
+
52
+ print '\n'
53
+ newBook = Spreadsheet::Workbook.new
54
+ newSheet = newBook.create_worksheet
55
+
56
+ newSheet.name = "output"
57
+
58
+ testvar = Array.new
59
+
60
+ print "~>looking for unnecessary information"
61
+ print "\n"
62
+ sheet1.row(0).each_with_index{|val, index|
63
+
64
+ 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"
65
+ testvar.push(index)
66
+ end
67
+ }
68
+
69
+ unless sheet1.row(0).include? "OppCommunity"
70
+ print "you are missing the OppCommunity field\n".upcase
71
+ else
72
+
73
+ end
74
+ unless sheet1.row(0).include? "FirstName"
75
+ print "you are missing the FirstName field\n".upcase
76
+ end
77
+ unless sheet1.row(0).include? "LastName"
78
+ print "you are missing the LastName field\n".upcase
79
+ end
80
+ unless sheet1.row(0).include? "Phone"
81
+ print "you are missing the phone field\n".upcase
82
+ end
83
+ unless sheet1.row(0).include? "Address"
84
+ print "you are missing the Address field\n".upcase
85
+ end
86
+ unless sheet1.row(0).include? "City"
87
+ print "you are missing the City field\n".upcase
88
+ end
89
+ unless sheet1.row(0).include? "State"
90
+ print "you are missing the State field\n".upcase
91
+ end
92
+ unless sheet1.row(0).include? "Zipcode"
93
+ print "you are missing the Zipcode field\n".upcase
94
+ end
95
+ unless sheet1.row(0).include? "Address"
96
+ print "you are missing the Address field\n".upcase
97
+ end
98
+ unless sheet1.row(0).include? "Address"
99
+ print "you are missing the Address field\n".upcase
100
+ end
101
+ unless sheet1.row(0).include? "Email"
102
+ print "you are missing the Email field\n".upcase
103
+ end
104
+ # puts testvar
105
+ newvar = Array.new
106
+ newvar.push "zero"
107
+ sheet1.each do |row|
108
+ row.each_with_index {|val, index|
109
+ if testvar.include? index
110
+
111
+ newvar.push val
112
+ end
113
+ }
114
+ end
115
+ print "~~>writing new file \n\n"
116
+ # print newvar
117
+ newvar.map! { |x|
118
+
119
+ if x == "OppCommunity"
120
+ print "renaming field #{x} \n"
121
+ x = "Community"
122
+ elsif x == "FirstName"
123
+ print "renaming field #{x} \n"
124
+ x = "First Name"
125
+ elsif x == "LastName"
126
+ print "renaming field #{x} \n"
127
+ x = "Last Name"
128
+ elsif x == "Address"
129
+ print "renaming field #{x} \n"
130
+ x = "Address"
131
+ elsif x == "city"
132
+ print "renaming field #{x} \n"
133
+ x = "city"
134
+ elsif x == "State"
135
+ print "renaming field #{x} \n"
136
+ x = "State"
137
+ elsif x == "Zipcode"
138
+ print "renaming field #{x} \n"
139
+ x = "Zipcode"
140
+ elsif x == "Email"
141
+ print "renaming field #{x} \n"
142
+ x = "Email"
143
+ else
144
+ x=x
145
+ end
146
+ }
147
+ # print newvar
148
+ for i in 0..newvar.length
149
+ for j in 1..testvar.length
150
+
151
+
152
+ newSheet.row(i).push newvar[(i*testvar.length)+j]
153
+ end
154
+ end
155
+ print "output file is in same file under out.xls to open, use \n \n open #{output}"
156
+ print "\n"
157
+ newBook.write output
158
+ end
159
+ end
160
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prune-erickson
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alejandro Londono
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: spreadsheet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.7
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.7
33
+ description: An excel processing script to remove erroneous data
34
+ email: alejandro.londono@erickson.com
35
+ executables:
36
+ - prune-erickson
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - bin/prune-erickson
41
+ - lib/prune-erickson.rb
42
+ homepage:
43
+ licenses:
44
+ - apache
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.4.6
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: prune-erickson
66
+ test_files: []