Sha256: 3aa488efdab35ddae7dd4daead12bee69c7aee53af805cc89f29e89e8f906805
Contents?: true
Size: 1.67 KB
Versions: 12
Compression:
Stored size: 1.67 KB
Contents
module WordCountAnalyzer class Hyperlink NON_HYPERLINK_REGEX = /\A\w+:$/ # Rubular: http://rubular.com/r/fXa4lp0gfS HYPERLINK_REGEX = /(http|https|www)(\.|:)/ attr_reader :string def initialize(string:) @string = string end def hyperlink? !(string !~ URI.regexp) && string !~ NON_HYPERLINK_REGEX && !(string !~ HYPERLINK_REGEX) end def occurences counter = 0 string.scan(URI.regexp).each do |link| counter += 1 if link.compact.size > 1 end counter end def replace new_string = string.dup string.split(/\s+/).each do |token| if !(token !~ URI.regexp) && token !~ NON_HYPERLINK_REGEX && !(token !~ HYPERLINK_REGEX) && token.include?('">') new_string = new_string.gsub(/#{Regexp.escape(token.split('">')[0])}/, ' wslinkword ') elsif !(token !~ URI.regexp) && token !~ NON_HYPERLINK_REGEX && !(token !~ HYPERLINK_REGEX) new_string = new_string.gsub(/#{Regexp.escape(token)}/, ' wslinkword ') end end new_string end def replace_split_at_period new_string = string.dup string.split(/\s+/).each do |token| if !(token !~ URI.regexp) && token !~ NON_HYPERLINK_REGEX && !(token !~ HYPERLINK_REGEX) && token.include?('">') new_string.gsub!(/#{Regexp.escape(token.split('">')[0])}/) do |match| match.split('.').join(' ') end elsif !(token !~ URI.regexp) && token !~ NON_HYPERLINK_REGEX && !(token !~ HYPERLINK_REGEX) new_string.gsub!(/#{Regexp.escape(token)}/) do |match| match.split('.').join(' ') end end end new_string end end end
Version data entries
12 entries across 12 versions & 1 rubygems