tb 0.8 → 0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/README +14 -7
  3. data/bin/tb +3 -3
  4. data/lib/tb.rb +3 -3
  5. data/lib/tb/basic.rb +34 -34
  6. data/lib/tb/catreader.rb +3 -3
  7. data/lib/tb/cmd_cat.rb +5 -5
  8. data/lib/tb/cmd_consecutive.rb +4 -4
  9. data/lib/tb/cmd_crop.rb +4 -4
  10. data/lib/tb/cmd_cross.rb +3 -3
  11. data/lib/tb/cmd_cut.rb +3 -3
  12. data/lib/tb/cmd_git.rb +3 -3
  13. data/lib/tb/cmd_grep.rb +3 -3
  14. data/lib/tb/cmd_group.rb +3 -3
  15. data/lib/tb/cmd_gsub.rb +3 -3
  16. data/lib/tb/cmd_help.rb +3 -3
  17. data/lib/tb/cmd_join.rb +3 -3
  18. data/lib/tb/cmd_ls.rb +3 -3
  19. data/lib/tb/cmd_melt.rb +3 -3
  20. data/lib/tb/cmd_mheader.rb +3 -3
  21. data/lib/tb/cmd_nest.rb +3 -3
  22. data/lib/tb/cmd_newfield.rb +17 -7
  23. data/lib/tb/cmd_rename.rb +3 -3
  24. data/lib/tb/cmd_shape.rb +3 -3
  25. data/lib/tb/cmd_sort.rb +3 -3
  26. data/lib/tb/cmd_svn.rb +3 -3
  27. data/lib/tb/cmd_tar.rb +3 -3
  28. data/lib/tb/cmd_to_csv.rb +4 -4
  29. data/lib/tb/cmd_to_json.rb +3 -3
  30. data/lib/tb/cmd_to_ltsv.rb +4 -4
  31. data/lib/tb/cmd_to_pnm.rb +3 -3
  32. data/lib/tb/cmd_to_pp.rb +3 -3
  33. data/lib/tb/cmd_to_tsv.rb +4 -4
  34. data/lib/tb/cmd_to_yaml.rb +3 -3
  35. data/lib/tb/cmd_unmelt.rb +3 -3
  36. data/lib/tb/cmd_unnest.rb +5 -4
  37. data/lib/tb/cmdmain.rb +3 -3
  38. data/lib/tb/cmdtop.rb +3 -3
  39. data/lib/tb/cmdutil.rb +3 -3
  40. data/lib/tb/csv.rb +10 -4
  41. data/lib/tb/customcmp.rb +3 -3
  42. data/lib/tb/customeq.rb +3 -3
  43. data/lib/tb/enumerable.rb +3 -3
  44. data/lib/tb/enumerator.rb +3 -3
  45. data/lib/tb/ex_enumerable.rb +2 -2
  46. data/lib/tb/ex_enumerator.rb +4 -4
  47. data/lib/tb/fieldset.rb +3 -3
  48. data/lib/tb/fileenumerator.rb +6 -6
  49. data/lib/tb/func.rb +3 -3
  50. data/lib/tb/json.rb +3 -3
  51. data/lib/tb/ltsv.rb +32 -7
  52. data/lib/tb/pnm.rb +3 -3
  53. data/lib/tb/reader.rb +3 -3
  54. data/lib/tb/record.rb +3 -3
  55. data/lib/tb/revcmp.rb +3 -3
  56. data/lib/tb/ropen.rb +23 -23
  57. data/lib/tb/search.rb +7 -7
  58. data/lib/tb/tsv.rb +3 -3
  59. data/lib/tb/zipper.rb +3 -3
  60. data/sample/excel2csv +36 -36
  61. data/sample/poi-xls2csv.rb +78 -78
  62. data/sample/poi-xls2csv.sh +3 -3
  63. data/sample/tbplot +214 -112
  64. data/test/test_basic.rb +4 -4
  65. data/test/test_cmd_newfield.rb +17 -3
  66. data/test/test_ex_enumerable.rb +18 -18
  67. data/test/test_ltsv.rb +8 -0
  68. metadata +5 -5
@@ -1,9 +1,9 @@
1
1
  # Copyright (C) 2012 Tanaka Akira <akr@fsij.org>
2
- #
2
+ #
3
3
  # Redistribution and use in source and binary forms, with or without
4
4
  # modification, are permitted provided that the following conditions
5
5
  # are met:
6
- #
6
+ #
7
7
  # 1. Redistributions of source code must retain the above copyright
8
8
  # notice, this list of conditions and the following disclaimer.
9
9
  # 2. Redistributions in binary form must reproduce the above
@@ -13,7 +13,7 @@
13
13
  # 3. The name of the author may not be used to endorse or promote
14
14
  # products derived from this software without specific prior
15
15
  # written permission.
16
- #
16
+ #
17
17
  # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18
18
  # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
19
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -1,9 +1,9 @@
1
1
  # Copyright (C) 2012 Tanaka Akira <akr@fsij.org>
2
- #
2
+ #
3
3
  # Redistribution and use in source and binary forms, with or without
4
4
  # modification, are permitted provided that the following conditions
5
5
  # are met:
6
- #
6
+ #
7
7
  # 1. Redistributions of source code must retain the above copyright
8
8
  # notice, this list of conditions and the following disclaimer.
9
9
  # 2. Redistributions in binary form must reproduce the above
@@ -13,7 +13,7 @@
13
13
  # 3. The name of the author may not be used to endorse or promote
14
14
  # products derived from this software without specific prior
15
15
  # written permission.
16
- #
16
+ #
17
17
  # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18
18
  # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
19
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -1,11 +1,11 @@
1
1
  # lib/tb/ltsv.rb - LTSV related fetures for table library
2
2
  #
3
3
  # Copyright (C) 2013 Tanaka Akira <akr@fsij.org>
4
- #
4
+ #
5
5
  # Redistribution and use in source and binary forms, with or without
6
6
  # modification, are permitted provided that the following conditions
7
7
  # are met:
8
- #
8
+ #
9
9
  # 1. Redistributions of source code must retain the above copyright
10
10
  # notice, this list of conditions and the following disclaimer.
11
11
  # 2. Redistributions in binary form must reproduce the above
@@ -15,7 +15,7 @@
15
15
  # 3. The name of the author may not be used to endorse or promote
16
16
  # products derived from this software without specific prior
17
17
  # written permission.
18
- #
18
+ #
19
19
  # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20
20
  # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
21
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -62,9 +62,9 @@ class Tb
62
62
  nil
63
63
  end
64
64
 
65
- def Tb.ltsv_escape_string(str)
65
+ def Tb.ltsv_escape_key(str)
66
66
  if /[\0-\x1f":\\\x7f]/ =~ str
67
- '"' +
67
+ '"' +
68
68
  str.gsub(/[\0-\x1f":\\\x7f]/) {
69
69
  ch = $&
70
70
  case ch
@@ -87,11 +87,36 @@ class Tb
87
87
  end
88
88
  end
89
89
 
90
+ def Tb.ltsv_escape_value(str)
91
+ if /[\0-\x1f"\\\x7f]/ =~ str
92
+ '"' +
93
+ str.gsub(/[\0-\x1f"\\\x7f]/) {
94
+ ch = $&
95
+ case ch
96
+ when "\0"; '\0'
97
+ when "\a"; '\a'
98
+ when "\b"; '\b'
99
+ when "\f"; '\f'
100
+ when "\n"; '\n'
101
+ when "\r"; '\r'
102
+ when "\t"; '\t'
103
+ when "\v"; '\v'
104
+ when "\e"; '\e'
105
+ else
106
+ "\\x%02X" % ch.ord
107
+ end
108
+ } +
109
+ '"'
110
+ else
111
+ str
112
+ end
113
+ end
114
+
90
115
  def Tb.ltsv_unescape_string(str)
91
116
  if /\A\s*"(.*)"\s*\z/ =~ str
92
117
  $1.gsub(/\\([0abfnrtve]|x([0-9A-Fa-f][0-9A-Fa-f]))/) {
93
118
  if $2
94
- [$2.to_i].pack("H2")
119
+ [$2].pack("H2")
95
120
  else
96
121
  case $1
97
122
  when "0"; "\0"
@@ -181,7 +206,7 @@ class Tb
181
206
 
182
207
  def Tb.ltsv_assoc_join(assoc)
183
208
  assoc.map {|key, val|
184
- Tb.ltsv_escape_string(key) + ':' + Tb.ltsv_escape_string(val)
209
+ Tb.ltsv_escape_key(key) + ':' + Tb.ltsv_escape_value(val)
185
210
  }.join("\t")
186
211
  end
187
212
  end
@@ -1,11 +1,11 @@
1
1
  # lib/tb/pnm.rb - tools for (very small) PNM images.
2
2
  #
3
3
  # Copyright (C) 2010-2012 Tanaka Akira <akr@fsij.org>
4
- #
4
+ #
5
5
  # Redistribution and use in source and binary forms, with or without
6
6
  # modification, are permitted provided that the following conditions
7
7
  # are met:
8
- #
8
+ #
9
9
  # 1. Redistributions of source code must retain the above copyright
10
10
  # notice, this list of conditions and the following disclaimer.
11
11
  # 2. Redistributions in binary form must reproduce the above
@@ -15,7 +15,7 @@
15
15
  # 3. The name of the author may not be used to endorse or promote
16
16
  # products derived from this software without specific prior
17
17
  # written permission.
18
- #
18
+ #
19
19
  # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20
20
  # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
21
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -1,11 +1,11 @@
1
1
  # lib/tb/reader.rb - Tb::Reader class
2
2
  #
3
3
  # Copyright (C) 2011-2012 Tanaka Akira <akr@fsij.org>
4
- #
4
+ #
5
5
  # Redistribution and use in source and binary forms, with or without
6
6
  # modification, are permitted provided that the following conditions
7
7
  # are met:
8
- #
8
+ #
9
9
  # 1. Redistributions of source code must retain the above copyright
10
10
  # notice, this list of conditions and the following disclaimer.
11
11
  # 2. Redistributions in binary form must reproduce the above
@@ -15,7 +15,7 @@
15
15
  # 3. The name of the author may not be used to endorse or promote
16
16
  # products derived from this software without specific prior
17
17
  # written permission.
18
- #
18
+ #
19
19
  # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20
20
  # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
21
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -1,11 +1,11 @@
1
1
  # lib/tb/record.rb - record class for table library
2
2
  #
3
3
  # Copyright (C) 2010-2012 Tanaka Akira <akr@fsij.org>
4
- #
4
+ #
5
5
  # Redistribution and use in source and binary forms, with or without
6
6
  # modification, are permitted provided that the following conditions
7
7
  # are met:
8
- #
8
+ #
9
9
  # 1. Redistributions of source code must retain the above copyright
10
10
  # notice, this list of conditions and the following disclaimer.
11
11
  # 2. Redistributions in binary form must reproduce the above
@@ -15,7 +15,7 @@
15
15
  # 3. The name of the author may not be used to endorse or promote
16
16
  # products derived from this software without specific prior
17
17
  # written permission.
18
- #
18
+ #
19
19
  # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20
20
  # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
21
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -1,9 +1,9 @@
1
1
  # Copyright (C) 2012 Tanaka Akira <akr@fsij.org>
2
- #
2
+ #
3
3
  # Redistribution and use in source and binary forms, with or without
4
4
  # modification, are permitted provided that the following conditions
5
5
  # are met:
6
- #
6
+ #
7
7
  # 1. Redistributions of source code must retain the above copyright
8
8
  # notice, this list of conditions and the following disclaimer.
9
9
  # 2. Redistributions in binary form must reproduce the above
@@ -13,7 +13,7 @@
13
13
  # 3. The name of the author may not be used to endorse or promote
14
14
  # products derived from this software without specific prior
15
15
  # written permission.
16
- #
16
+ #
17
17
  # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18
18
  # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
19
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -1,11 +1,11 @@
1
1
  # lib/tb/ropen.rb - Tb::Reader.open
2
2
  #
3
3
  # Copyright (C) 2011-2013 Tanaka Akira <akr@fsij.org>
4
- #
4
+ #
5
5
  # Redistribution and use in source and binary forms, with or without
6
6
  # modification, are permitted provided that the following conditions
7
7
  # are met:
8
- #
8
+ #
9
9
  # 1. Redistributions of source code must retain the above copyright
10
10
  # notice, this list of conditions and the following disclaimer.
11
11
  # 2. Redistributions in binary form must reproduce the above
@@ -15,7 +15,7 @@
15
15
  # 3. The name of the author may not be used to endorse or promote
16
16
  # products derived from this software without specific prior
17
17
  # written permission.
18
- #
18
+ #
19
19
  # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20
20
  # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
21
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -33,58 +33,58 @@ def Tb.open_reader(filename, opts={})
33
33
  case filename
34
34
  when /\Acsv:/
35
35
  filename = $'
36
- rawreader_maker_for_tb_reader = lambda {|io| Tb::CSVReader.new(io) }
36
+ table_reader_maker = lambda {|io| Tb::CSVReader.new(io) }
37
37
  when /\Atsv:/
38
38
  filename = $'
39
- rawreader_maker_for_tb_reader = lambda {|io| Tb::TSVReader.new(io) }
39
+ table_reader_maker = lambda {|io| Tb::TSVReader.new(io) }
40
40
  when /\Altsv:/
41
41
  filename = $'
42
- rawreader_maker_for_tb_reader = lambda {|io| Tb::LTSVReader.new(io) }
42
+ pairs_reader_maker = lambda {|io| Tb::LTSVReader.new(io) }
43
43
  when /\Ap[pgbn]m:/
44
44
  filename = $'
45
- rawreader_maker_for_tb_reader = lambda {|io| Tb.pnm_stream_input(io) }
45
+ table_reader_maker = lambda {|io| Tb.pnm_stream_input(io) }
46
46
  when /\Ajson:/
47
47
  filename = $'
48
- json_reader_maker = lambda {|io| Tb::JSONReader.new(io.read) }
48
+ whole_reader_maker = lambda {|io| Tb::JSONReader.new(io.read) }
49
49
  when /\.csv\z/
50
- rawreader_maker_for_tb_reader = lambda {|io| Tb::CSVReader.new(io) }
50
+ table_reader_maker = lambda {|io| Tb::CSVReader.new(io) }
51
51
  when /\.tsv\z/
52
- rawreader_maker_for_tb_reader = lambda {|io| Tb::TSVReader.new(io) }
52
+ table_reader_maker = lambda {|io| Tb::TSVReader.new(io) }
53
53
  when /\.ltsv\z/
54
- reader_maker_for_tb_reader = lambda {|io| Tb::LTSVReader.new(io) }
54
+ pairs_reader_maker = lambda {|io| Tb::LTSVReader.new(io) }
55
55
  when /\.p[pgbn]m\z/
56
- rawreader_maker_for_tb_reader = lambda {|io| Tb.pnm_stream_input(io) }
56
+ table_reader_maker = lambda {|io| Tb.pnm_stream_input(io) }
57
57
  when /\.json\z/
58
- json_reader_maker = lambda {|io| Tb::JSONReader.new(io.read) }
58
+ whole_reader_maker = lambda {|io| Tb::JSONReader.new(io.read) }
59
59
  else
60
- rawreader_maker_for_tb_reader = lambda {|io| Tb::CSVReader.new(io) }
60
+ table_reader_maker = lambda {|io| Tb::CSVReader.new(io) }
61
61
  end
62
62
  if !filename.respond_to?(:to_str) && !filename.respond_to?(:to_path)
63
63
  raise ArgumentError, "unexpected filename: #{filename.inspect}"
64
64
  end
65
- if json_reader_maker
65
+ if whole_reader_maker
66
66
  if filename == '-'
67
- reader = json_reader_maker.call($stdin)
67
+ reader = whole_reader_maker.call($stdin)
68
68
  else
69
69
  reader = File.open(filename) {|io|
70
- json_reader_maker.call(io)
70
+ whole_reader_maker.call(io)
71
71
  }
72
72
  end
73
- elsif reader_maker_for_tb_reader
73
+ elsif pairs_reader_maker
74
74
  if filename == '-'
75
- reader = reader_maker_for_tb_reader.call($stdin)
75
+ reader = pairs_reader_maker.call($stdin)
76
76
  else
77
- reader = reader_maker_for_tb_reader.call(File.open(filename))
77
+ reader = pairs_reader_maker.call(File.open(filename))
78
78
  end
79
79
  else
80
- # rawreader_maker_for_tb_reader should be available.
80
+ # table_reader_maker should be available.
81
81
  reader = Tb::Reader.new(opts) {|body|
82
82
  if filename == '-'
83
- rawreader = rawreader_maker_for_tb_reader.call($stdin)
83
+ rawreader = table_reader_maker.call($stdin)
84
84
  body.call(rawreader)
85
85
  else
86
86
  File.open(filename) {|io|
87
- rawreader = rawreader_maker_for_tb_reader.call(io)
87
+ rawreader = table_reader_maker.call(io)
88
88
  body.call(rawreader)
89
89
  }
90
90
  end
@@ -1,11 +1,11 @@
1
1
  # lib/tb/search.rb - pattern matcher for two-dimensional array.
2
2
  #
3
3
  # Copyright (C) 2011-2012 Tanaka Akira <akr@fsij.org>
4
- #
4
+ #
5
5
  # Redistribution and use in source and binary forms, with or without
6
6
  # modification, are permitted provided that the following conditions
7
7
  # are met:
8
- #
8
+ #
9
9
  # 1. Redistributions of source code must retain the above copyright
10
10
  # notice, this list of conditions and the following disclaimer.
11
11
  # 2. Redistributions in binary form must reproduce the above
@@ -15,7 +15,7 @@
15
15
  # 3. The name of the author may not be used to endorse or promote
16
16
  # products derived from this software without specific prior
17
17
  # written permission.
18
- #
18
+ #
19
19
  # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20
20
  # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
21
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -144,7 +144,7 @@ module Tb::Search
144
144
  #
145
145
  # However try_rmove permits movement to/from outside of _aa_.
146
146
  # It don't permit between two position outside of _aa_, though.
147
- # This make match [:rep, "a", :e] to %w[a a a] with three "a"s.
147
+ # This make match [:rep, "a", :e] to %w[a a a] with three "a"s.
148
148
  # If try_rmove don't permit movement to outside of _aa_,
149
149
  # the last movement is forbidden.
150
150
  #
@@ -215,7 +215,7 @@ module Tb::Search
215
215
  visited2[st.values_at(*visit_keys)] = true
216
216
  result = []
217
217
  if min <= 0 && !greedy
218
- result << lambda {
218
+ result << lambda {
219
219
  st = st.merge(var => visited.size) if var
220
220
  yield st
221
221
  }
@@ -256,7 +256,7 @@ module Tb::Search
256
256
  result = []
257
257
  result << lambda {
258
258
  yield st
259
- }
259
+ }
260
260
  result << lambda {
261
261
  try_cat(ps, aa, st) {|st2|
262
262
  k = st2.values_at(*keys)
@@ -269,7 +269,7 @@ module Tb::Search
269
269
  }
270
270
  result << lambda {
271
271
  try_bfs_loop(queue, visited, keys, ps, aa, &b)
272
- }
272
+ }
273
273
  result
274
274
  end
275
275
  end
@@ -1,11 +1,11 @@
1
1
  # lib/tb/tsv.rb - TSV related fetures for table library
2
2
  #
3
3
  # Copyright (C) 2010-2012 Tanaka Akira <akr@fsij.org>
4
- #
4
+ #
5
5
  # Redistribution and use in source and binary forms, with or without
6
6
  # modification, are permitted provided that the following conditions
7
7
  # are met:
8
- #
8
+ #
9
9
  # 1. Redistributions of source code must retain the above copyright
10
10
  # notice, this list of conditions and the following disclaimer.
11
11
  # 2. Redistributions in binary form must reproduce the above
@@ -15,7 +15,7 @@
15
15
  # 3. The name of the author may not be used to endorse or promote
16
16
  # products derived from this software without specific prior
17
17
  # written permission.
18
- #
18
+ #
19
19
  # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20
20
  # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
21
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -1,9 +1,9 @@
1
1
  # Copyright (C) 2012 Tanaka Akira <akr@fsij.org>
2
- #
2
+ #
3
3
  # Redistribution and use in source and binary forms, with or without
4
4
  # modification, are permitted provided that the following conditions
5
5
  # are met:
6
- #
6
+ #
7
7
  # 1. Redistributions of source code must retain the above copyright
8
8
  # notice, this list of conditions and the following disclaimer.
9
9
  # 2. Redistributions in binary form must reproduce the above
@@ -13,7 +13,7 @@
13
13
  # 3. The name of the author may not be used to endorse or promote
14
14
  # products derived from this software without specific prior
15
15
  # written permission.
16
- #
16
+ #
17
17
  # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18
18
  # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
19
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -3,11 +3,11 @@
3
3
  # sample/excel2csv - XLS to CSV converter using Microsoft Excel via WIN32OLE.
4
4
  #
5
5
  # Copyright (C) 2011-2012 Tanaka Akira <akr@fsij.org>
6
- #
6
+ #
7
7
  # Redistribution and use in source and binary forms, with or without
8
8
  # modification, are permitted provided that the following conditions
9
9
  # are met:
10
- #
10
+ #
11
11
  # 1. Redistributions of source code must retain the above copyright
12
12
  # notice, this list of conditions and the following disclaimer.
13
13
  # 2. Redistributions in binary form must reproduce the above
@@ -17,7 +17,7 @@
17
17
  # 3. The name of the author may not be used to endorse or promote
18
18
  # products derived from this software without specific prior
19
19
  # written permission.
20
- #
20
+ #
21
21
  # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22
22
  # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23
23
  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -85,9 +85,9 @@ def convert_cell(cell)
85
85
  val = cell.MergeArea.Item(1,1).Value
86
86
  if $opt_mergecells == 'topleft'
87
87
  if c_row == m_row && c_col == m_col
88
- v = val
88
+ v = val
89
89
  else
90
- v = nil
90
+ v = nil
91
91
  end
92
92
  else
93
93
  v = val
@@ -114,43 +114,43 @@ def convert_horizontal_borders(sheet_xrange, sheet_yrange, usedrange, upper_y)
114
114
  upperleft_cell = (sheet_yrange.include?(usedrange_yoff+upper_y) && sheet_yrange.include?(usedrange_xoff+left_x)) ?
115
115
  usedrange.Cells(upper_y, left_x) : nil
116
116
  upperright_cell = (sheet_yrange.include?(usedrange_yoff+upper_y) && sheet_xrange.include?(usedrange_xoff+right_x)) ?
117
- usedrange.Cells(upper_y, right_x) : nil
117
+ usedrange.Cells(upper_y, right_x) : nil
118
118
  lowerleft_cell = (sheet_yrange.include?(usedrange_yoff+lower_y) && sheet_xrange.include?(usedrange_xoff+left_x)) ?
119
119
  usedrange.Cells(lower_y, left_x) : nil
120
120
  lowerright_cell = (sheet_yrange.include?(usedrange_yoff+lower_y) && sheet_xrange.include?(usedrange_xoff+right_x)) ?
121
- usedrange.Cells(lower_y, right_x) : nil
121
+ usedrange.Cells(lower_y, right_x) : nil
122
122
  upper_line = lower_line = left_line = right_line = false
123
123
  if (!upperleft_cell || !upperright_cell ||
124
124
  !upperleft_cell.MergeCells || !upperright_cell.MergeCells ||
125
- upperleft_cell.MergeArea.Row != upperright_cell.MergeArea.Row ||
126
- upperleft_cell.MergeArea.Column != upperright_cell.MergeArea.Column) &&
125
+ upperleft_cell.MergeArea.Row != upperright_cell.MergeArea.Row ||
126
+ upperleft_cell.MergeArea.Column != upperright_cell.MergeArea.Column) &&
127
127
  ((upperleft_cell && upperleft_cell.borders(Excel::XlEdgeRight).linestyle != Excel::XlNone) ||
128
128
  (upperright_cell && upperright_cell.borders(Excel::XlEdgeLeft).linestyle != Excel::XlNone))
129
- upper_line = true
129
+ upper_line = true
130
130
  end
131
131
  if (!lowerleft_cell || !lowerright_cell ||
132
132
  !lowerleft_cell.MergeCells || !lowerright_cell.MergeCells ||
133
- lowerleft_cell.MergeArea.Row != lowerright_cell.MergeArea.Row ||
134
- lowerleft_cell.MergeArea.Column != lowerright_cell.MergeArea.Column) &&
133
+ lowerleft_cell.MergeArea.Row != lowerright_cell.MergeArea.Row ||
134
+ lowerleft_cell.MergeArea.Column != lowerright_cell.MergeArea.Column) &&
135
135
  ((lowerleft_cell && lowerleft_cell.borders(Excel::XlEdgeRight).linestyle != Excel::XlNone) ||
136
136
  (lowerright_cell && lowerright_cell.borders(Excel::XlEdgeLeft).linestyle != Excel::XlNone))
137
- lower_line = true
137
+ lower_line = true
138
138
  end
139
139
  if (!upperleft_cell || !lowerleft_cell ||
140
140
  !upperleft_cell.MergeCells || !lowerleft_cell.MergeCells ||
141
- upperleft_cell.MergeArea.Row != lowerleft_cell.MergeArea.Row ||
142
- upperleft_cell.MergeArea.Column != lowerleft_cell.MergeArea.Column) &&
141
+ upperleft_cell.MergeArea.Row != lowerleft_cell.MergeArea.Row ||
142
+ upperleft_cell.MergeArea.Column != lowerleft_cell.MergeArea.Column) &&
143
143
  ((upperleft_cell && upperleft_cell.borders(Excel::XlEdgeBottom).linestyle != Excel::XlNone) ||
144
144
  (lowerleft_cell && lowerleft_cell.borders(Excel::XlEdgeTop).linestyle != Excel::XlNone))
145
- left_line = true
145
+ left_line = true
146
146
  end
147
147
  if (!upperright_cell || !lowerright_cell ||
148
148
  !upperright_cell.MergeCells || !lowerright_cell.MergeCells ||
149
- upperright_cell.MergeArea.Row != lowerright_cell.MergeArea.Row ||
150
- upperright_cell.MergeArea.Column != lowerright_cell.MergeArea.Column) &&
149
+ upperright_cell.MergeArea.Row != lowerright_cell.MergeArea.Row ||
150
+ upperright_cell.MergeArea.Column != lowerright_cell.MergeArea.Column) &&
151
151
  ((upperright_cell && upperright_cell.borders(Excel::XlEdgeBottom).linestyle != Excel::XlNone) ||
152
152
  (lowerright_cell && lowerright_cell.borders(Excel::XlEdgeTop).linestyle != Excel::XlNone))
153
- right_line = true
153
+ right_line = true
154
154
  end
155
155
  if upper_line && lower_line && !left_line && !right_line
156
156
  joint = '|'
@@ -170,8 +170,8 @@ def convert_horizontal_borders(sheet_xrange, sheet_yrange, usedrange, upper_y)
170
170
  lower_cell = (0 < lower_y) ? usedrange.Cells(lower_y, cell_x) : nil
171
171
  if (!upper_cell || !lower_cell ||
172
172
  !upper_cell.MergeCells || !lower_cell.MergeCells ||
173
- upper_cell.MergeArea.Row != lower_cell.MergeArea.Row ||
174
- upper_cell.MergeArea.Column != lower_cell.MergeArea.Column) &&
173
+ upper_cell.MergeArea.Row != lower_cell.MergeArea.Row ||
174
+ upper_cell.MergeArea.Column != lower_cell.MergeArea.Column) &&
175
175
  ((upper_cell && upper_cell.borders(Excel::XlEdgeBottom).linestyle != Excel::XlNone) ||
176
176
  (lower_cell && lower_cell.borders(Excel::XlEdgeTop).linestyle != Excel::XlNone))
177
177
  hborder = '-'
@@ -247,25 +247,25 @@ begin
247
247
  ARGV.each {|excel_filename|
248
248
  if File.directory? excel_filename
249
249
  filenames = []
250
- Find.find(excel_filename) {|path| filenames << path if /\.xls\z/ =~ path }
250
+ Find.find(excel_filename) {|path| filenames << path if /\.xls\z/ =~ path }
251
251
  else
252
252
  filenames = [excel_filename]
253
253
  end
254
254
  filenames.each {|ifn0|
255
- ifn = getAbsolutePath(ifn0)
256
- wb = excel.Workbooks.Open(ifn)
257
- begin
258
- if $opt_all_sheets
259
- wb.Worksheets.each {|sheet|
260
- sheetname = sheet.Name
261
- convert_sheet(ifn0, sheet, csvgen)
262
- }
263
- else
264
- convert_sheet(ifn0, wb.Worksheets(1), csvgen)
265
- end
266
- ensure
267
- wb.Close
268
- end
255
+ ifn = getAbsolutePath(ifn0)
256
+ wb = excel.Workbooks.Open(ifn)
257
+ begin
258
+ if $opt_all_sheets
259
+ wb.Worksheets.each {|sheet|
260
+ sheetname = sheet.Name
261
+ convert_sheet(ifn0, sheet, csvgen)
262
+ }
263
+ else
264
+ convert_sheet(ifn0, wb.Worksheets(1), csvgen)
265
+ end
266
+ ensure
267
+ wb.Close
268
+ end
269
269
  }
270
270
  }
271
271
  }