Class: CodeStock::Grep

Inherits:
Object
  • Object
show all
Defined in:
lib/codestock/cdweb/lib/grep.rb

Defined Under Namespace

Classes: MatchLineResult

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Grep

Returns a new instance of Grep.



10
11
12
# File 'lib/codestock/cdweb/lib/grep.rb', line 10

def initialize(content)
  @content = content
end

Instance Method Details

#match_lines_and(patterns) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/codestock/cdweb/lib/grep.rb', line 16

def match_lines_and(patterns)
  result = []
  patternRegexps = strs2regs(patterns, true)
  index = 0
  
  @content.each_line do |line|
    match_datas = []
    patternRegexps.each {|v| match_datas << v.match(line)}

    if (match_datas.all?)
      result << MatchLineResult.new(index, match_datas)
    end

    index += 1
  end
  
  result
end

#one_match_and(patterns) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/codestock/cdweb/lib/grep.rb', line 35

def one_match_and(patterns)
  patternRegexps = strs2regs(patterns, true)
  index = 0
  
  @content.each_line do |line|
    match_datas = []
    patternRegexps.each {|v| match_datas << v.match(line)}

    if (match_datas.all?)
      return MatchLineResult.new(index, match_datas)
    end

    index += 1
  end
  
  nil
end