workbook 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -3
  3. data/lib/workbook/book.rb +13 -12
  4. data/lib/workbook/column.rb +13 -6
  5. data/lib/workbook/format.rb +16 -1
  6. data/lib/workbook/modules/cell.rb +3 -2
  7. data/lib/workbook/modules/diff_sort.rb +2 -2
  8. data/lib/workbook/modules/type_parser.rb +3 -2
  9. data/lib/workbook/readers/xls_reader.rb +4 -4
  10. data/lib/workbook/readers/xls_shared.rb +39 -0
  11. data/lib/workbook/readers/xlsx_reader.rb +159 -21
  12. data/lib/workbook/row.rb +2 -2
  13. data/lib/workbook/sheet.rb +9 -2
  14. data/lib/workbook/table.rb +20 -8
  15. data/lib/workbook/template.rb +5 -1
  16. data/lib/workbook/types/date.rb +1 -1
  17. data/lib/workbook/version.rb +1 -1
  18. data/lib/workbook/writers/xlsx_writer.rb +7 -7
  19. data/test/artifacts/txt_in_xls.xls +0 -0
  20. data/test/test_book.rb +7 -6
  21. data/test/test_format.rb +10 -0
  22. data/test/test_functional.rb +3 -3
  23. data/test/test_modules_cell.rb +19 -11
  24. data/test/test_modules_table_diff_sort.rb +0 -2
  25. data/test/test_modules_type_parser.rb +7 -5
  26. data/test/test_readers_csv_reader.rb +4 -4
  27. data/test/test_readers_ods_reader.rb +9 -9
  28. data/test/test_readers_txt_reader.rb +5 -5
  29. data/test/test_readers_xls_reader.rb +11 -15
  30. data/test/test_readers_xls_shared.rb +10 -0
  31. data/test/test_readers_xlsx_reader.rb +12 -9
  32. data/test/test_row.rb +6 -6
  33. data/test/test_table.rb +13 -11
  34. data/test/test_template.rb +10 -1
  35. data/test/test_types_date.rb +3 -0
  36. data/test/test_writers_html_writer.rb +1 -1
  37. data/test/test_writers_xls_writer.rb +9 -10
  38. data/test/test_writers_xlsx_writer.rb +2 -2
  39. data/workbook.gemspec +0 -1
  40. metadata +4 -18
  41. data/rbeautify.rb +0 -234
data/rbeautify.rb DELETED
@@ -1,234 +0,0 @@
1
- #!/usr/bin/ruby -w
2
-
3
-
4
- =begin
5
- /***************************************************************************
6
- * Copyright (C) 2008, Paul Lutus *
7
- * *
8
- * This program is free software; you can redistribute it and/or modify *
9
- * it under the terms of the GNU General Public License as published by *
10
- * the Free Software Foundation; either version 2 of the License, or *
11
- * (at your option) any later version. *
12
- * *
13
- * This program is distributed in the hope that it will be useful, *
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16
- * GNU General Public License for more details. *
17
- * *
18
- * You should have received a copy of the GNU General Public License *
19
- * along with this program; if not, write to the *
20
- * Free Software Foundation, Inc., *
21
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22
- ***************************************************************************/
23
-
24
- To recursively execute this script run: `find . -name "*.rb"|xargs ./rbeautify.rb`
25
- =end
26
-
27
- PVERSION = "Version 2.9, 10/24/2008"
28
-
29
- module RBeautify
30
-
31
- # user-customizable values
32
-
33
- RBeautify::TabStr = " "
34
- RBeautify::TabSize = 2
35
-
36
- # indent regexp tests
37
-
38
- IndentExp = [
39
- /^module\b/,
40
- /^class\b/,
41
- /^if\b/,
42
- /(=\s*|^)until\b/,
43
- /(=\s*|^)for\b/,
44
- /^unless\b/,
45
- /(=\s*|^)while\b/,
46
- /(=\s*|^)begin\b/,
47
- /(^| )case\b/,
48
- /\bthen\b/,
49
- /^rescue\b/,
50
- /^def\b/,
51
- /\bdo\b/,
52
- /^else\b/,
53
- /^elsif\b/,
54
- /^ensure\b/,
55
- /\bwhen\b/,
56
- /\{[^\}]*$/,
57
- /\[[^\]]*$/
58
- ]
59
-
60
- # outdent regexp tests
61
-
62
- OutdentExp = [
63
- /^rescue\b/,
64
- /^ensure\b/,
65
- /^elsif\b/,
66
- /^end\b/,
67
- /^else\b/,
68
- /\bwhen\b/,
69
- /^[^\{]*\}/,
70
- /^[^\[]*\]/
71
- ]
72
-
73
- def RBeautify.rb_make_tab(tab)
74
- return (tab < 0)?"":TabStr * TabSize * tab
75
- end
76
-
77
- def RBeautify.rb_add_line(line,tab)
78
- line.strip!
79
- line = rb_make_tab(tab) + line if line.length > 0
80
- return line
81
- end
82
-
83
- def RBeautify.beautify_string(source, path = "")
84
- comment_block = false
85
- in_here_doc = false
86
- here_doc_term = ""
87
- program_end = false
88
- multiLine_array = []
89
- multiLine_str = ""
90
- tab = 0
91
- output = []
92
- source.each_line do |line|
93
- line.chomp!
94
- if(!program_end)
95
- # detect program end mark
96
- if(line =~ /^__END__$/)
97
- program_end = true
98
- else
99
- # combine continuing lines
100
- if(!(line =~ /^\s*#/) && line =~ /[^\\]\\\s*$/)
101
- multiLine_array.push line
102
- multiLine_str += line.sub(/^(.*)\\\s*$/,"\\1")
103
- next
104
- end
105
-
106
- # add final line
107
- if(multiLine_str.length > 0)
108
- multiLine_array.push line
109
- multiLine_str += line.sub(/^(.*)\\\s*$/,"\\1")
110
- end
111
-
112
- tline = ((multiLine_str.length > 0)?multiLine_str:line).strip
113
- if(tline =~ /^=begin/)
114
- comment_block = true
115
- end
116
- if(in_here_doc)
117
- in_here_doc = false if tline =~ %r{\s*#{here_doc_term}\s*}
118
- else # not in here_doc
119
- if tline =~ %r{=\s*<<}
120
- here_doc_term = tline.sub(%r{.*=\s*<<-?\s*([\w]+).*},"\\1")
121
- in_here_doc = here_doc_term.size > 0
122
- end
123
- end
124
- end
125
- end
126
- if(comment_block || program_end || in_here_doc)
127
- # add the line unchanged
128
- output << line
129
- else
130
- comment_line = (tline =~ /^#/)
131
- if(!comment_line)
132
- # throw out sequences that will
133
- # only sow confusion
134
- while tline.gsub!(/\{[^\{]*?\}/,"")
135
- end
136
- while tline.gsub!(/\[[^\[]*?\]/,"")
137
- end
138
- while tline.gsub!(/'.*?'/,"")
139
- end
140
- while tline.gsub!(/".*?"/,"")
141
- end
142
- while tline.gsub!(/\`.*?\`/,"")
143
- end
144
- while tline.gsub!(/\([^\(]*?\)/,"")
145
- end
146
- while tline.gsub!(/\/.*?\//,"")
147
- end
148
- while tline.gsub!(/%r(.).*?\1/,"")
149
- end
150
- # delete end-of-line comments
151
- tline.sub!(/#[^\"]+$/,"")
152
- # convert quotes
153
- tline.gsub!(/\\\"/,"'")
154
- OutdentExp.each do |re|
155
- if(tline =~ re)
156
- tab -= 1
157
- break
158
- end
159
- end
160
- end
161
- if (multiLine_array.length > 0)
162
- multiLine_array.each do |ml|
163
- output << rb_add_line(ml,tab)
164
- end
165
- multiLine_array.clear
166
- multiLine_str = ""
167
- else
168
- output << rb_add_line(line,tab)
169
- end
170
- if(!comment_line)
171
- IndentExp.each do |re|
172
- if(tline =~ re && !(tline =~ /\s+end\s*$/))
173
- tab += 1
174
- break
175
- end
176
- end
177
- end
178
- end
179
- if(tline =~ /^=end/)
180
- comment_block = false
181
- end
182
- end
183
- error = (tab != 0)
184
- STDERR.puts "#{path}: Error: indent/outdent mismatch: #{tab}." if error
185
- return output.join("\n") + "\n",error
186
- end # beautify_string
187
-
188
- def RBeautify.beautify_file(path, check)
189
- error = false
190
- if(path == '-') # stdin source
191
- source = STDIN.read
192
- dest,error = beautify_string(source,"stdin")
193
- print dest
194
- else # named file source
195
- source = File.read(path)
196
- dest,error = beautify_string(source,path)
197
- if(source != dest && !error)
198
- if check
199
- puts "#{path} needs formatting"
200
- error = "formatting"
201
- else
202
- # make a backup copy
203
- File.open(path + "~","w") { |f| f.write(source) }
204
- # overwrite the original
205
- File.open(path,"w") { |f| f.write(dest) }
206
- end
207
- end
208
- end
209
- return error
210
- end # beautify_file
211
-
212
- def RBeautify.main
213
- error = false
214
- check = false
215
- if(!ARGV[0])
216
- STDERR.puts "usage: Ruby filenames or \"-\" for stdin."
217
- exit 0
218
- end
219
- if ARGV[0] == '--check'
220
- check = true
221
- ARGV.slice!(0)
222
- end
223
- ARGV.each do |argument|
224
- error = (beautify_file(argument, check))?true:error
225
- end
226
- error = (error)?1:0
227
- exit error
228
- end # main
229
- end # module RBeautify
230
-
231
- # if launched as a standalone program, not loaded as a module
232
- if __FILE__ == $0
233
- RBeautify.main
234
- end