Class: Onebox::Matcher

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

Instance Method Summary collapse

Constructor Details

#initialize(link, options = {}) ⇒ Matcher

Returns a new instance of Matcher.



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

def initialize(link, options = {})
  @url = link
  @options = options
end

Instance Method Details

#has_allowed_iframe_origins?(engine) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/onebox/matcher.rb', line 25

def has_allowed_iframe_origins?(engine)
  allowed_regexes = @options[:allowed_iframe_regexes] || []
  engine.iframe_origins.all? { |o| allowed_regexes.any? { |r| o =~ r } }
end

#oneboxedObject



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

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 && has_allowed_iframe_origins?(engine) }
rescue URI::InvalidURIError
  nil
end

#ordered_enginesObject



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

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