Class: Titi::Matcher::MatchRegexpRepeatedly

Inherits:
Base
  • Object
show all
Defined in:
lib/titi/ignore/matcher.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#matcher, #options, #selector

Instance Method Summary collapse

Constructor Details

#initialize(selector, re, matcher = nil) ⇒ MatchRegexpRepeatedly

Returns a new instance of MatchRegexpRepeatedly.



183
184
185
186
# File 'lib/titi/ignore/matcher.rb', line 183

def initialize selector, re, matcher=nil
  super selector, matcher
  self.re = re
end

Instance Attribute Details

#reObject

Returns the value of attribute re.



182
183
184
# File 'lib/titi/ignore/matcher.rb', line 182

def re
  @re
end

Instance Method Details

#match(doc) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/titi/ignore/matcher.rb', line 187

def match doc
  doc = Hpricot(doc) if doc.is_a?(String)
  # apply selector, if any
  el = selector ? doc.contents_of(selector) : doc
  return unless el
  # get all matches
  val = el.to_s.scan(re)
  # if there's only one capture group, flatten the array
  val = val.flatten if val.first && val.first.length == 1
  # pass to matcher, if any
  matcher ? matcher.match(val) : val
end