Sha256: e6993b89ea287c83a4eaedc2e3615c2bbfa8e5efa23882f451238842de96a86e

Contents?: true

Size: 693 Bytes

Versions: 16

Compression:

Stored size: 693 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)

      # A onebox needs a path, query or fragment string to be considered
      return if (uri.query.nil? || uri.query.size == 0) &&
                (uri.fragment.nil? || uri.fragment.size == 0) &&
                (uri.path.size == 0 || uri.path == "/")

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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
onebox-1.6.9 lib/onebox/matcher.rb
onebox-1.6.8 lib/onebox/matcher.rb
onebox-1.6.7 lib/onebox/matcher.rb
onebox-1.6.6 lib/onebox/matcher.rb
onebox-1.6.5 lib/onebox/matcher.rb
onebox-1.6.4 lib/onebox/matcher.rb
onebox-1.6.3 lib/onebox/matcher.rb
onebox-1.6.2 lib/onebox/matcher.rb
onebox-1.6.1 lib/onebox/matcher.rb
onebox-1.6.0 lib/onebox/matcher.rb
onebox-1.5.65 lib/onebox/matcher.rb
onebox-1.5.64 lib/onebox/matcher.rb
onebox-1.5.63 lib/onebox/matcher.rb
onebox-1.5.62 lib/onebox/matcher.rb
onebox-1.5.61 lib/onebox/matcher.rb
onebox-1.5.60 lib/onebox/matcher.rb