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-2.0.2 lib/onebox/matcher.rb
onebox-2.0.1 lib/onebox/matcher.rb
onebox-1.9.30 lib/onebox/matcher.rb
onebox-1.9.29 lib/onebox/matcher.rb
onebox-1.9.28.4 lib/onebox/matcher.rb
onebox-1.9.28.3 lib/onebox/matcher.rb
onebox-1.9.28.2 lib/onebox/matcher.rb
onebox-1.9.28.1 lib/onebox/matcher.rb
onebox-1.9.28 lib/onebox/matcher.rb
onebox-1.9.27.2 lib/onebox/matcher.rb
onebox-1.9.27.1 lib/onebox/matcher.rb
onebox-1.9.26 lib/onebox/matcher.rb
onebox-1.9.25 lib/onebox/matcher.rb
onebox-1.9.24 lib/onebox/matcher.rb
onebox-1.9.23 lib/onebox/matcher.rb
onebox-1.9.22 lib/onebox/matcher.rb
onebox-1.9.21 lib/onebox/matcher.rb
onebox-1.9.20 lib/onebox/matcher.rb
onebox-1.9.19 lib/onebox/matcher.rb
onebox-1.9.18 lib/onebox/matcher.rb