Class: Scrubber
- Inherits:
-
Object
- Object
- Scrubber
- Defined in:
- lib/scrubber.rb
Instance Method Summary collapse
- #config {|@config| ... } ⇒ Object
-
#initialize(&block) ⇒ Scrubber
constructor
A new instance of Scrubber.
- #scrub(data, splitter = /\n/) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Scrubber
Returns a new instance of Scrubber.
2 3 4 |
# File 'lib/scrubber.rb', line 2 def initialize(&block) config(&block) if block_given? end |
Instance Method Details
#config {|@config| ... } ⇒ Object
6 7 8 9 |
# File 'lib/scrubber.rb', line 6 def config @config = Scrub::Config.new yield @config end |
#scrub(data, splitter = /\n/) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/scrubber.rb', line 11 def scrub(data, splitter = /\n/) lines = data.split(splitter) while(line = lines.shift) line.strip! @config.matchers.each do |matcher, prok| prok.call(line) if line =~ matcher end @config.between_matchers.each do |matcher, | if line =~ matcher end_matcher, prok, conditions = next_line = nil while(next_line = lines.shift) && (next_line !~ end_matcher) prok.call(next_line) if next_line =~ conditions[:when] end end end end end |