class NetworkProfile::Extractor

Constants

Logic from: github.com/tenderlove/rails_autolink/blob/master/lib/rails_autolink/helpers.rb

BRACKETS
HOST_PART
TLD
WORD_PATTERN

Public Class Methods

call(string) click to toggle source
# File lib/network_profile/extractor.rb, line 12
def self.call(string)
  new(string).extracted_links!
end
new(string) click to toggle source
# File lib/network_profile/extractor.rb, line 16
def initialize(string)
  @string = string
end

Public Instance Methods

mapped_string() click to toggle source
# File lib/network_profile/extractor.rb, line 54
def mapped_string
  @string.
    gsub(%r{ (#{HOST_PART}\.#{TLD}/)}) { |_|
      host = Regexp.last_match['host']
      "https://#{host}.#{Regexp.last_match['tld']}/"
    }.
    gsub(%r{ www *\. +#{HOST_PART} *\. *#{TLD}(?<path>[^<\u00A0"]+)}) { |_|
      path = Regexp.last_match['path'].remove(' ')
      "www.#{Regexp.last_match['host']}.#{Regexp.last_match['tld']}#{path}"
    }
end