Sha256: 54b27c3e4ea9a8944ffce67cd8b3717fdd81b76effb81b558565c1a53fd3f353

Contents?: true

Size: 595 Bytes

Versions: 48

Compression:

Stored size: 595 Bytes

Contents

# frozen_string_literal: true

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)
      return unless uri.port.nil? || Onebox.options.allowed_ports.include?(uri.port)
      return unless uri.scheme.nil? || Onebox.options.allowed_schemes.include?(uri.scheme)
      ordered_engines.find { |engine| engine === uri }
    rescue URI::InvalidURIError
      nil
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
onebox-1.9.17 lib/onebox/matcher.rb
onebox-1.9.16 lib/onebox/matcher.rb
onebox-1.9.15 lib/onebox/matcher.rb
onebox-1.9.14 lib/onebox/matcher.rb
onebox-1.9.13 lib/onebox/matcher.rb
onebox-1.9.12 lib/onebox/matcher.rb
onebox-1.9.11 lib/onebox/matcher.rb
onebox-1.9.10 lib/onebox/matcher.rb
onebox-1.9.9 lib/onebox/matcher.rb
onebox-1.9.8 lib/onebox/matcher.rb
onebox-1.9.7 lib/onebox/matcher.rb
onebox-1.9.6 lib/onebox/matcher.rb
onebox-1.9.5 lib/onebox/matcher.rb
onebox-1.9.4 lib/onebox/matcher.rb
onebox-1.9.3 lib/onebox/matcher.rb
onebox-1.9.2 lib/onebox/matcher.rb
onebox-1.9.1 lib/onebox/matcher.rb
onebox-1.9.0 lib/onebox/matcher.rb
onebox-1.8.99 lib/onebox/matcher.rb
onebox-1.8.98 lib/onebox/matcher.rb