Sha256: 4dbcf0f94613d6360fe6033849bc9c53455715dace1c2f8dc31c980cf19e9a61

Contents?: true

Size: 718 Bytes

Versions: 44

Compression:

Stored size: 718 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.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

44 entries across 44 versions & 1 rubygems

Version Path
onebox-1.5.29 lib/onebox/matcher.rb
onebox-1.5.28 lib/onebox/matcher.rb
onebox-1.5.27 lib/onebox/matcher.rb
onebox-1.5.26 lib/onebox/matcher.rb
onebox-1.5.25 lib/onebox/matcher.rb
onebox-1.5.24 lib/onebox/matcher.rb
onebox-1.5.23 lib/onebox/matcher.rb
onebox-1.5.22 lib/onebox/matcher.rb
onebox-1.5.21 lib/onebox/matcher.rb
onebox-1.5.20 lib/onebox/matcher.rb
onebox-1.5.19 lib/onebox/matcher.rb
onebox-1.5.18 lib/onebox/matcher.rb
onebox-1.5.17 lib/onebox/matcher.rb
onebox-1.5.16 lib/onebox/matcher.rb
onebox-1.5.14 lib/onebox/matcher.rb
onebox-1.5.13 lib/onebox/matcher.rb
onebox-1.5.12 lib/onebox/matcher.rb
onebox-1.5.11 lib/onebox/matcher.rb
onebox-1.5.10 lib/onebox/matcher.rb
onebox-1.5.9 lib/onebox/matcher.rb