Class: Onebox::Matcher
- Inherits:
-
Object
- Object
- Onebox::Matcher
- Defined in:
- lib/onebox/matcher.rb
Instance Method Summary collapse
- #has_allowed_iframe_origins?(engine) ⇒ Boolean
-
#initialize(url, options = {}) ⇒ Matcher
constructor
A new instance of Matcher.
- #oneboxed ⇒ Object
- #ordered_engines ⇒ Object
Constructor Details
#initialize(url, options = {}) ⇒ Matcher
Returns a new instance of Matcher.
5 6 7 8 9 10 11 12 |
# File 'lib/onebox/matcher.rb', line 5 def initialize(url, = {}) begin @uri = URI(url) rescue URI::InvalidURIError end @options = end |
Instance Method Details
#has_allowed_iframe_origins?(engine) ⇒ Boolean
27 28 29 30 |
# File 'lib/onebox/matcher.rb', line 27 def has_allowed_iframe_origins?(engine) allowed_regexes = @options[:allowed_iframe_regexes] || [] engine.iframe_origins.all? { |o| allowed_regexes.any? { |r| o =~ r } } end |
#oneboxed ⇒ Object
20 21 22 23 24 25 |
# File 'lib/onebox/matcher.rb', line 20 def oneboxed return if @uri.nil? return if @uri.port && !Onebox..allowed_ports.include?(@uri.port) return if @uri.scheme && !Onebox..allowed_schemes.include?(@uri.scheme) ordered_engines.find { |engine| engine === @uri && has_allowed_iframe_origins?(engine) } end |