Sha256: bd08748b09c212f84933aae65cd61126c167f56c63aa122b98b1a53e4cb48d65

Contents?: true

Size: 643 Bytes

Versions: 23

Compression:

Stored size: 643 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 or query string to be considered
      return if (uri.query.nil? || uri.query.size == 0) &&
                (uri.path.size == 0 || uri.path == "/")

      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

23 entries across 23 versions & 1 rubygems

Version Path
onebox-1.5.3 lib/onebox/matcher.rb
onebox-1.5.2 lib/onebox/matcher.rb
onebox-1.5.1 lib/onebox/matcher.rb
onebox-1.5.0 lib/onebox/matcher.rb
onebox-1.4.9 lib/onebox/matcher.rb
onebox-1.4.8 lib/onebox/matcher.rb
onebox-1.4.7 lib/onebox/matcher.rb
onebox-1.4.5 lib/onebox/matcher.rb
onebox-1.4.4 lib/onebox/matcher.rb
onebox-1.4.3 lib/onebox/matcher.rb
onebox-1.4.2 lib/onebox/matcher.rb
onebox-1.4.1 lib/onebox/matcher.rb
onebox-1.4.0 lib/onebox/matcher.rb
onebox-1.3.9 lib/onebox/matcher.rb
onebox-1.3.8 lib/onebox/matcher.rb
onebox-1.3.7 lib/onebox/matcher.rb
onebox-1.3.6 lib/onebox/matcher.rb
onebox-1.3.5 lib/onebox/matcher.rb
onebox-1.3.4 lib/onebox/matcher.rb
onebox-1.3.3 lib/onebox/matcher.rb