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.



5
6
7
# File 'lib/onebox/matcher.rb', line 5

def initialize(link)
  @url = link
end

Instance Method Details

#oneboxedObject



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

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



9
10
11
12
13
# File 'lib/onebox/matcher.rb', line 9

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