class UrlParser

Parses text and attempts to find urls

Constants

BAD_URL_REGEX

Public Instance Methods

count_url_instances(text, options) click to toggle source

Counts the number of occurrences of that url within the block of text

# File lib/ramparts/parsers/url_parser.rb, line 8
def count_url_instances(text, options)
  raise ArgumentError, ARGUMENT_ERROR_TEXT unless text.is_a? String

  text = parse_url(text)
  url_instances(text, options).length
end

Private Instance Methods

parse_url(text) click to toggle source

Parses the url to make it easier to search

# File lib/ramparts/parsers/url_parser.rb, line 20
def parse_url(text)
  text.downcase
end
url_instances(text, _options) click to toggle source

Returns the instances that match the regex

# File lib/ramparts/parsers/url_parser.rb, line 25
def url_instances(text, _options)
  text
    .enum_for(:scan, BAD_URL_REGEX)
    .map { { offset: Regexp.last_match.begin(0), value: Regexp.last_match.to_s.strip } }
end