Sha256: 51889f8739455005d678957f5d8cd02df11bab5ead50d139e3aeb2dc0ee3bfbf
Contents?: true
Size: 766 Bytes
Versions: 2
Compression:
Stored size: 766 Bytes
Contents
# frozen_string_literal: true require_relative '../helpers' # Parses text and attempts to find urls class UrlParser # Counts the number of occurrences of that url within the block of text 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 BAD_URL_REGEX = Regexp.union(/cialis/, /viagra/) # Parses the url to make it easier to search def parse_url(text) text.downcase end # Returns the instances that match the regex 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 end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
ramparts-0.3.1 | lib/ramparts/parsers/url_parser.rb |
ramparts-0.3.0 | lib/ramparts/parsers/url_parser.rb |