processr 0.9.2 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.2
1
+ 0.9.5
data/examples/all.rb CHANGED
@@ -1,5 +1,6 @@
1
- require 'rubygems'
2
- require 'processr'
1
+ #require 'rubygems'
2
+ #require 'processr'
3
+ require '../lib/processr'
3
4
 
4
5
  # Setup
5
6
 
@@ -17,7 +18,7 @@ processor << "Some More Text"
17
18
  puts processor.process!
18
19
 
19
20
 
20
- puts "Simple text concatenation form files:"
21
+ puts "Simple text concatenation from files:"
21
22
 
22
23
  processor = Processr.new
23
24
  processor.files << File.join('..', 'spec', 'fixtures', 'one.txt')
@@ -46,3 +47,38 @@ processor = Processr.new
46
47
  processor.add_filter(TextileFilter)
47
48
  processor << 'A _simple_ example of a "textile":http://www.textism.com/tools/textile/ parser using a *filter*.'
48
49
  puts processor.process!
50
+
51
+
52
+ puts "Simple language filter using input:"
53
+
54
+ LanguageFilter = lambda do |buffer|
55
+ lookup = [
56
+ "fucking",
57
+ "hate"
58
+ ]
59
+
60
+ lookup.each do |word|
61
+ buffer.gsub!(word, ("*" * word.size))
62
+ end
63
+
64
+ buffer
65
+ end
66
+
67
+ processor = Processr.new
68
+ processor.add_filter(LanguageFilter)
69
+ processor << 'I fucking hate bad language.'
70
+ puts processor.process!
71
+
72
+
73
+ puts "Simple text concatenation from files with file filters:"
74
+
75
+ InBetweenFilter = lambda do |filename, contents|
76
+ puts "Filter for #{filename}"
77
+ contents
78
+ end
79
+
80
+ processor = Processr.new
81
+ processor.file_filters << InBetweenFilter
82
+ processor.files << File.join('..', 'spec', 'fixtures', 'one.txt')
83
+ processor.files << File.join('..', 'spec', 'fixtures', 'two.txt')
84
+ puts processor.process!
data/lib/processr.rb CHANGED
@@ -14,12 +14,13 @@ class Processr
14
14
  end
15
15
  end
16
16
 
17
- attr_accessor :buffer, :files, :filters
17
+ attr_accessor :buffer, :files, :filters, :file_filters
18
18
 
19
19
  def initialize
20
20
  self.buffer = ""
21
21
  self.files = []
22
22
  self.filters = []
23
+ self.file_filters = []
23
24
  end
24
25
 
25
26
  def add_filter(filter)
@@ -43,8 +44,14 @@ class Processr
43
44
  end
44
45
  end
45
46
 
46
- def read_file_to_buffer(file)
47
- self.buffer << File.open(File.join(self.class.root, file)).read
47
+ def read_file_to_buffer(filename)
48
+ contents = File.open(File.join(self.class.root, filename)).read
49
+
50
+ self.file_filters.each do |filter|
51
+ contents = filter.call(filename, contents)
52
+ end
53
+
54
+ self.buffer << contents
48
55
  end
49
56
 
50
57
  def process_filters
data/processr.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{processr}
8
- s.version = "0.9.2"
8
+ s.version = "0.9.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Josh Nesbitt"]
12
- s.date = %q{2010-07-13}
12
+ s.date = %q{2010-09-21}
13
13
  s.description = %q{Processr is a simple text processing and concatenation library. It takes a number of input strings (or files) and outputs a single string (or file) containing the result. Text can be passed through filters to modify the output.}
14
14
  s.email = %q{josh@josh-nesbitt.net}
15
15
  s.extra_rdoc_files = [
@@ -36,7 +36,7 @@ Gem::Specification.new do |s|
36
36
  s.homepage = %q{http://github.com/joshnesbitt/processr}
37
37
  s.rdoc_options = ["--charset=UTF-8"]
38
38
  s.require_paths = ["lib"]
39
- s.rubygems_version = %q{1.3.6}
39
+ s.rubygems_version = %q{1.3.7}
40
40
  s.summary = %q{A simple text processing library}
41
41
  s.test_files = [
42
42
  "spec/lib/processr_spec.rb",
@@ -49,7 +49,7 @@ Gem::Specification.new do |s|
49
49
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
50
  s.specification_version = 3
51
51
 
52
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
52
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
53
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
54
54
  else
55
55
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
@@ -78,4 +78,13 @@ describe Processr do
78
78
  @processor.process!.should == "I ******* **** bad language."
79
79
  end
80
80
 
81
+ it "should allow the use of inbetween filters to modify file buffer content" do
82
+ Processr.out = nil
83
+ @processor.buffer.should == ""
84
+ @processor.file_filters << lambda { |filename, contents| contents + "{mod}" }
85
+ @processor.files << File.join('fixtures', 'one.txt')
86
+ @processor.files << File.join('fixtures', 'two.txt')
87
+ @processor.process!.should == "one\n{mod}two\n{mod}"
88
+ end
89
+
81
90
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: processr
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 49
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 9
8
- - 2
9
- version: 0.9.2
9
+ - 5
10
+ version: 0.9.5
10
11
  platform: ruby
11
12
  authors:
12
13
  - Josh Nesbitt
@@ -14,16 +15,18 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-07-13 00:00:00 +01:00
18
+ date: 2010-09-21 00:00:00 +01:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: rspec
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 13
27
30
  segments:
28
31
  - 1
29
32
  - 2
@@ -66,23 +69,27 @@ rdoc_options:
66
69
  require_paths:
67
70
  - lib
68
71
  required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
69
73
  requirements:
70
74
  - - ">="
71
75
  - !ruby/object:Gem::Version
76
+ hash: 3
72
77
  segments:
73
78
  - 0
74
79
  version: "0"
75
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
76
82
  requirements:
77
83
  - - ">="
78
84
  - !ruby/object:Gem::Version
85
+ hash: 3
79
86
  segments:
80
87
  - 0
81
88
  version: "0"
82
89
  requirements: []
83
90
 
84
91
  rubyforge_project:
85
- rubygems_version: 1.3.6
92
+ rubygems_version: 1.3.7
86
93
  signing_key:
87
94
  specification_version: 3
88
95
  summary: A simple text processing library