class TextDetector::Detector::Regexp

Public Instance Methods

detect(text) click to toggle source
# File lib/text_detector/detector/regexp.rb, line 6
def detect(text)
  matched = @re.match(TextDetector.normalize(text))
  if matched
    offset = matched.offset(0)
    text.slice(offset[0], offset[1] - offset[0])
  else
    nil
  end
end
detect_all(text) click to toggle source
# File lib/text_detector/detector/regexp.rb, line 16
def detect_all(text)
  TextDetector.normalize(text).to_enum(:scan, @re).map do
    offset = ::Regexp.last_match.offset(0)
    text.slice(offset[0], offset[1] - offset[0])
  end
end

Protected Instance Methods

setup() click to toggle source
# File lib/text_detector/detector/regexp.rb, line 25
def setup
  @re = ::Regexp.union(dictionary.members)
end