Class: Grenweb::Grep

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

Defined Under Namespace

Classes: MatchLineResult

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Grep

Returns a new instance of Grep.



12
13
14
# File 'lib/cdweb/grep.rb', line 12

def initialize(content)
  @content = content.split("\n")
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

Instance Method Details

#context(result, num) ⇒ Object



34
35
# File 'lib/cdweb/grep.rb', line 34

def context(result, num)
end

#match_lines_or(patterns) ⇒ Object



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

def match_lines_or(patterns)
  result = []
  patternRegexps = strs2regs(patterns, true) # @todo ignoreオプションを付ける
  
  @content.each_with_index do |line, index|
    match_datas = []
    patternRegexps.each {|v| match_datas << v.match(line)}

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