scrub 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,3 +1,8 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+
1
6
  begin
2
7
  require 'jeweler'
3
8
  Jeweler::Tasks.new do |gemspec|
@@ -11,3 +16,10 @@ begin
11
16
  rescue LoadError
12
17
  puts "Jeweler not available. Install it with: sudo gem install jeweler"
13
18
  end
19
+
20
+ Rake::TestTask.new do |t|
21
+ t.libs = %w(test)
22
+ t.pattern = 'test/**/*_test.rb'
23
+ end
24
+
25
+ task :default => :test
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -13,14 +13,22 @@ class Scrubber
13
13
  while(line = lines.shift)
14
14
  line.strip!
15
15
  @config.matchers.each do |matcher, prok|
16
- prok.call(line) if line =~ matcher
16
+ if match = line.match(matcher)
17
+ prok.call(line, *match.captures)
18
+ end
17
19
  end
18
20
  @config.between_matchers.each do |matcher, options|
19
21
  if line =~ matcher
20
22
  end_matcher, prok, conditions = options
21
23
  next_line = nil
22
24
  while(next_line = lines.shift) && (next_line !~ end_matcher)
23
- prok.call(next_line) if next_line =~ conditions[:when]
25
+ if conditions[:when]
26
+ if match = next_line.match(conditions[:when])
27
+ prok.call(next_line, *match.captures)
28
+ end
29
+ else
30
+ prok.call(next_line)
31
+ end
24
32
  end
25
33
  end
26
34
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{scrub}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matthew Mongeau"]
@@ -19,13 +19,21 @@ Gem::Specification.new do |s|
19
19
  "VERSION",
20
20
  "lib/scrub.rb",
21
21
  "lib/scrubber.rb",
22
- "scrub.gemspec"
22
+ "scrub.gemspec",
23
+ "test/fixtures/file1.txt",
24
+ "test/fixtures/file2.txt",
25
+ "test/scrubber_test.rb",
26
+ "test/test_helper.rb"
23
27
  ]
24
28
  s.homepage = %q{http://github.com/toastyapps/scrub}
25
29
  s.rdoc_options = ["--charset=UTF-8"]
26
30
  s.require_paths = ["lib"]
27
31
  s.rubygems_version = %q{1.3.5}
28
32
  s.summary = %q{Scrub files with ease and elbow grease}
33
+ s.test_files = [
34
+ "test/scrubber_test.rb",
35
+ "test/test_helper.rb"
36
+ ]
29
37
 
30
38
  if s.respond_to? :specification_version then
31
39
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -0,0 +1,2 @@
1
+ a,b,c
2
+ 1,2,3
@@ -0,0 +1,5 @@
1
+ ---
2
+ a,b,c
3
+ 1,2,3
4
+ ---
5
+ d,e,f
@@ -0,0 +1,53 @@
1
+ require 'test_helper'
2
+
3
+ class ScrubberTest < Test::Unit::TestCase
4
+ def test_when
5
+ scrubber = Scrubber.new do |scrubber|
6
+ scrubber.when(/\d,\d,\d/) do |line|
7
+ assert_equal '1,2,3', line.strip
8
+ end
9
+ end
10
+ scrubber.scrub(File.read("fixtures/file1.txt"))
11
+ end
12
+
13
+ def test_when_with_var
14
+ scrubber = Scrubber.new do |scrubber|
15
+ scrubber.when(/([a-z]),[a-z],[a-z]/) do |line, var|
16
+ assert_equal 'a,b,c', line.strip
17
+ assert_equal 'a', var
18
+ end
19
+ end
20
+ scrubber.scrub(File.read("fixtures/file1.txt"))
21
+ end
22
+
23
+ def test_between
24
+ matches = ['a,b,c','1,2,3']
25
+ scrubber = Scrubber.new do |scrubber|
26
+ scrubber.between(/---/, /---/) do |line|
27
+ assert_equal matches.shift, line.strip
28
+ end
29
+ end
30
+ scrubber.scrub(File.read("fixtures/file2.txt"))
31
+ end
32
+
33
+ def test_between_with_when
34
+ scrubber = Scrubber.new do |scrubber|
35
+ scrubber.between(/---/, /---/, :when => /\d,\d,\d/) do |line|
36
+ assert_equal '1,2,3', line.strip
37
+ end
38
+ end
39
+ scrubber.scrub(File.read("fixtures/file2.txt"))
40
+ end
41
+
42
+ def test_between_with_when_and_var
43
+ matches = ['a,b,c','1,2,3']
44
+ var_matches = ['a', '1']
45
+ scrubber = Scrubber.new do |scrubber|
46
+ scrubber.between(/---/, /---/, :when => /(\w),\w,\w/) do |line, var|
47
+ assert_equal matches.shift, line.strip
48
+ assert_equal var_matches.shift, var
49
+ end
50
+ end
51
+ scrubber.scrub(File.read("fixtures/file2.txt"))
52
+ end
53
+ end
@@ -0,0 +1,4 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
2
+
3
+ require 'test/unit'
4
+ require 'scrub'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Mongeau
@@ -29,6 +29,10 @@ files:
29
29
  - lib/scrub.rb
30
30
  - lib/scrubber.rb
31
31
  - scrub.gemspec
32
+ - test/fixtures/file1.txt
33
+ - test/fixtures/file2.txt
34
+ - test/scrubber_test.rb
35
+ - test/test_helper.rb
32
36
  has_rdoc: true
33
37
  homepage: http://github.com/toastyapps/scrub
34
38
  licenses: []
@@ -57,5 +61,6 @@ rubygems_version: 1.3.5
57
61
  signing_key:
58
62
  specification_version: 3
59
63
  summary: Scrub files with ease and elbow grease
60
- test_files: []
61
-
64
+ test_files:
65
+ - test/scrubber_test.rb
66
+ - test/test_helper.rb