Sha256: 67735f22310cbd23558fc2f5a42dae7c42356f61d76c61083b644d22d8f9409c

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

# Get and filter links
module AwesomeBot
  class << self
    def links_filter(list)
      list.reject { |x| x.length < 9 }
        .map do |x|
          x.gsub(',','%2c').gsub(/'.*/, '').gsub(/,.*/, '')
        end
        .map do |x|
          if x.include? ')]'
            x.gsub /\)\].*/, ''
          elsif (x.scan(')').count == 2) && (x.scan('(').count == 1)
            x.gsub(/\)\).*/, ')')
          elsif (x.scan(')').count > 0)
            if (x.include? 'wikipedia')
              if (x.scan(')').count == 1) && (x.scan('(').count == 0)
                x.sub(').','').sub(')','')
              else
                x
              end
            else
              x.gsub(/\).*/, '')
            end
          elsif x.include? '[' # adoc
            x.gsub(/\[.*/, '')
          elsif x[-1]=='.' || x[-1]==':'
            x[0..-2]
          elsif x[-1]=='.'
            x[0..-2]
          elsif x[-3..-1]=='%2c'
            x[0..-4]
          else
            x
          end
        end
    end

    def links_find(content)
      require 'uri'
      URI.extract(content, /http()s?/)
    end
  end # class
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
awesome_bot-1.13.9 lib/awesome_bot/links.rb