class RegexpScan::Scanner

Public Class Methods

new(filter_regexp) click to toggle source
# File lib/regexp_scan/scanner.rb, line 2
def initialize(filter_regexp)
  @filter_regexp = to_regexp(filter_regexp)
  validation!
end

Public Instance Methods

execute(string) click to toggle source
# File lib/regexp_scan/scanner.rb, line 7
def execute(string)
  string.scan(/#{@filter_regexp}/)
end

Private Instance Methods

to_regexp(string_or_regexp) click to toggle source
# File lib/regexp_scan/scanner.rb, line 13
def to_regexp(string_or_regexp)
  case string_or_regexp
  when String
    Regexp.new(string_or_regexp)
  when Regexp
    string_or_regexp
  else
    nil
  end
end
validation!() click to toggle source
# File lib/regexp_scan/scanner.rb, line 24
def validation!
  unless @filter_regexp.is_a?(Regexp)
    raise ArgumentError.new('Expect Argument is Regexp or String')
  end
end