|
1 | 1 | require_relative 'dir_handler' |
2 | 2 |
|
3 | | -extensions = [ "cpp", "h", "hpp", "md" ] |
4 | | -extensions.freeze |
5 | | -dir = ARGV[0] |
6 | | -dir.freeze |
| 3 | +#extensions = [ "cpp", "h", "hpp", "md" ] |
| 4 | +#extensions.freeze |
| 5 | +#dir = ARGV[0] |
| 6 | +#dir.freeze |
| 7 | +# |
| 8 | +##init handlers for all types of files |
| 9 | +#handlers = extensions.collect{ |e| DirHandler.new dir, e } |
| 10 | +# |
| 11 | +##for comma: |
| 12 | +## 1,2,3,4 => 1, 2, 3, 4 |
| 13 | +#handlers.each do |h| |
| 14 | +# h.on_each_line do |line| |
| 15 | +# begin |
| 16 | +# line.gsub! /,(\S)/, ', \1' unless line.match /.*\".*,.*\".*/ or line.match /','/ |
| 17 | +# rescue Exception => e |
| 18 | +# puts e.message + ", ignored." |
| 19 | +# end |
| 20 | +# end |
| 21 | +#end |
| 22 | +# |
7 | 23 |
|
8 | | -#init handlers for all types of files |
9 | | -handlers = extensions.collect{ |e| DirHandler.new dir, e } |
| 24 | +class Format |
| 25 | + attr_reader :extensions |
10 | 26 |
|
11 | | -#for comma: |
12 | | -# 1,2,3,4 => 1, 2, 3, 4 |
13 | | -handlers.each do |h| |
14 | | - h.on_each_line do |line| |
15 | | - begin |
16 | | - line.gsub! /,(\S)/, ', \1' unless line.match /.*\".*,.*\".*/ or line.match /','/ |
17 | | - rescue Exception => e |
18 | | - puts e.message + ", ignored." |
19 | | - end |
| 27 | + def initialize dir, extensions |
| 28 | + @dir = dir |
| 29 | + @extensions = extensions |
| 30 | + @dir.freeze |
| 31 | + @extensions.freeze |
| 32 | + @handlers = extensions.collect{ |e| DirHandler.new dir, e } |
20 | 33 | end |
21 | | -end |
| 34 | + |
| 35 | + def for_commas |
| 36 | + @handlers.each do |h| |
| 37 | + h.on_each_line do |line| |
| 38 | + begin |
| 39 | + line.gsub! /,(\S)/, ', \1' unless line.match /.*\".*,.*\".*/ or line.match /','/ |
| 40 | + rescue Exception => e |
| 41 | + puts e.message + ", ignored." |
| 42 | + end |
| 43 | + end |
| 44 | + end |
| 45 | + end |
| 46 | +end |
| 47 | + |
| 48 | +format = Format.new ARGV[0], [ "cpp", "h", "hpp", "md" ] |
| 49 | +format.for_commas |
| 50 | + |
0 commit comments