Sha256: fa1fab32fbda01031894252427c97f6398fe6c4b50fa0736970566bf0067e41a

Contents?: true

Size: 464 Bytes

Versions: 5

Compression:

Stored size: 464 Bytes

Contents

module Onebox
  class Matcher
    def initialize(link)
      @url = link
    end

    def ordered_engines
      @ordered_engines ||= Engine.engines.sort_by do |e|
        e.respond_to?(:priority) ? e.priority : 100
      end
    end

    def oneboxed
      uri = URI(@url)

      ordered_engines.select do |engine|
        engine === uri
      end.first
    rescue URI::InvalidURIError
      # If it's not a valid URL, don't even match
      nil
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
onebox-1.2.9 lib/onebox/matcher.rb
onebox-1.2.8 lib/onebox/matcher.rb
onebox-1.2.7 lib/onebox/matcher.rb
onebox-1.2.6 lib/onebox/matcher.rb
onebox-1.2.5 lib/onebox/matcher.rb