Sha256: 830365e3f6386fe5a0b1f432a11280031343642629dc03952f235c6ff2efc9ee
Contents?: true
Size: 1.28 KB
Versions: 13
Compression:
Stored size: 1.28 KB
Contents
# -*- coding: utf-8 -*- # # @file # @brief grenwebで使用する行指向の検索 # @author ongaeshi # @date 2010/10/18 module Milkode class Grep def initialize(content) @content = content end MatchLineResult = Struct.new(:index, :match_datas) 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 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 private def strs2regs(strs, ignore = false) regs = [] strs.each do |v| option = 0 option |= Regexp::IGNORECASE if (ignore) regs << Regexp.new(v, option) end regs end end end
Version data entries
13 entries across 13 versions & 1 rubygems