Class: Milkode::Grep
- Inherits:
-
Object
- Object
- Milkode::Grep
- Defined in:
- lib/milkode/cdweb/lib/grep.rb
Instance Method Summary collapse
-
#initialize(content) ⇒ Grep
constructor
A new instance of Grep.
- #match_lines_and(patterns, is_sensitive, wide_match_range) ⇒ Object
- #match_lines_stopover(patterns, max_match, start_index, is_sensitive, wide_match_range) ⇒ Object
- #one_match_and(patterns, is_sensitive, wide_match_range) ⇒ Object
Constructor Details
#initialize(content) ⇒ Grep
Returns a new instance of Grep.
13 14 15 |
# File 'lib/milkode/cdweb/lib/grep.rb', line 13 def initialize(content) @content = content end |
Instance Method Details
#match_lines_and(patterns, is_sensitive, wide_match_range) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/milkode/cdweb/lib/grep.rb', line 46 def match_lines_and(patterns, is_sensitive, wide_match_range) regexps = strs2regs(patterns, is_sensitive) result = [] index = 0 matcher = WideMatcher.create(wide_match_range) @content.each_line do |line| matcher.add_line_matchs(index, match_regexps(line, regexps)) result += matcher.match_lines if matcher.match? index += 1 end result.uniq end |
#match_lines_stopover(patterns, max_match, start_index, is_sensitive, wide_match_range) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/milkode/cdweb/lib/grep.rb', line 17 def match_lines_stopover(patterns, max_match, start_index, is_sensitive, wide_match_range) regexps = strs2regs(patterns, is_sensitive) result = [] index = start_index matcher = WideMatcher.create(wide_match_range) lines = @content.split($/) while (index < lines.size) do line = lines[index] matcher.add_line_matchs(index, match_regexps(line, regexps)) if matcher.match? result += matcher.match_lines if result.size >= max_match index += 1 break end end index += 1 end index = 0 if (index >= lines.size) {:result => result.uniq, :next_line => index} end |
#one_match_and(patterns, is_sensitive, wide_match_range) ⇒ Object
62 63 64 |
# File 'lib/milkode/cdweb/lib/grep.rb', line 62 def one_match_and(patterns, is_sensitive, wide_match_range) match_lines_stopover(patterns, 1, 0, is_sensitive, wide_match_range) end |