Class: Onebox::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/onebox/matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(link) ⇒ Matcher

Returns a new instance of Matcher.


3
4
5
# File 'lib/onebox/matcher.rb', line 3

def initialize(link)
  @url = link
end

Instance Method Details

#oneboxedObject


13
14
15
16
17
18
19
20
# File 'lib/onebox/matcher.rb', line 13

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

#ordered_enginesObject


7
8
9
10
11
# File 'lib/onebox/matcher.rb', line 7

def ordered_engines
  @ordered_engines ||= Engine.engines.sort_by do |e|
    e.respond_to?(:priority) ? e.priority : 100
  end
end