troll 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,4 @@
1
+ require 'troll/semi_colon_troll'
2
+ require 'troll/tab_troll'
1
3
  require 'troll/collector'
2
4
  require 'troll/troller'
@@ -0,0 +1,24 @@
1
+ module Troll
2
+ class SemiColonTroll
3
+ def troll_string(str)
4
+ result = ""
5
+ str.each_line { |line| result += troll_line(line) }
6
+ result
7
+ end
8
+
9
+ private
10
+ def troll_line(line)
11
+ case line
12
+ when /^\s+$/
13
+ line
14
+ when /^.*[;,]\s*$/
15
+ line
16
+ when /^.*\n$/
17
+ "#{line.chomp};\n"
18
+ else
19
+ "#{line};"
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ module Troll
2
+ class TabTroll
3
+ def troll_string(str)
4
+ result = ""
5
+ str.each_line {|line| result += line.gsub(/( {2})/, " ")}
6
+ result
7
+ end
8
+ end
9
+ end
@@ -4,11 +4,15 @@ module Troll
4
4
 
5
5
  def initialize(file_path=nil)
6
6
  self.file = file_path
7
+ @trolls = [SemiColonTroll.new, TabTroll.new]
7
8
  end
8
9
 
9
10
  def troll
10
11
  contents = File.read(self.file)
11
- self.result = troll_string(contents)
12
+ @trolls.each do |troll|
13
+ contents = troll.troll_string(contents)
14
+ end
15
+ self.result = contents
12
16
  end
13
17
 
14
18
  def troll!
@@ -16,26 +20,7 @@ module Troll
16
20
  write_file
17
21
  end
18
22
 
19
- def troll_string(str)
20
- result = ""
21
- str.each_line { |line| result += troll_line(line) }
22
- result
23
- end
24
-
25
23
  private
26
- def troll_line(line)
27
- case line
28
- when /^\s+$/
29
- line
30
- when /^.*;\s*$/
31
- line
32
- when /^.*\n$/
33
- "#{line.chomp};\n"
34
- else
35
- "#{line};"
36
- end
37
- end
38
-
39
24
  def write_file
40
25
  File.open(output_file, 'w') do |f|
41
26
  f.puts self.result
@@ -1,3 +1,3 @@
1
1
  module Troll
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: troll
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-17 00:00:00.000000000 -07:00
12
+ date: 2011-09-19 00:00:00.000000000 -07:00
13
13
  default_executable: troll
14
14
  dependencies: []
15
15
  description: Trolling is a art
@@ -22,6 +22,8 @@ files:
22
22
  - README.md
23
23
  - bin/troll
24
24
  - lib/troll/collector.rb
25
+ - lib/troll/semi_colon_troll.rb
26
+ - lib/troll/tab_troll.rb
25
27
  - lib/troll/troller.rb
26
28
  - lib/troll/version.rb
27
29
  - lib/troll.rb