Class: Rack::Relations::Anchor
- Inherits:
-
Object
- Object
- Rack::Relations::Anchor
- Defined in:
- lib/rack/relations/anchor.rb
Instance Attribute Summary collapse
-
#node ⇒ Object
Returns the value of attribute node.
-
#safelist_domains ⇒ Object
Returns the value of attribute safelist_domains.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(node, safelist_domains:) ⇒ Anchor
constructor
A new instance of Anchor.
- #modified_rel ⇒ Object
- #safe? ⇒ Boolean
Constructor Details
#initialize(node, safelist_domains:) ⇒ Anchor
Returns a new instance of Anchor.
8 9 10 11 12 |
# File 'lib/rack/relations/anchor.rb', line 8 def initialize(node, safelist_domains:) @node = node @safelist_domains = safelist_domains @uri = URI(node.attr("href")) rescue nil end |
Instance Attribute Details
#node ⇒ Object
Returns the value of attribute node.
6 7 8 |
# File 'lib/rack/relations/anchor.rb', line 6 def node @node end |
#safelist_domains ⇒ Object
Returns the value of attribute safelist_domains.
6 7 8 |
# File 'lib/rack/relations/anchor.rb', line 6 def safelist_domains @safelist_domains end |
#uri ⇒ Object
Returns the value of attribute uri.
6 7 8 |
# File 'lib/rack/relations/anchor.rb', line 6 def uri @uri end |
Instance Method Details
#modified_rel ⇒ Object
14 15 16 |
# File 'lib/rack/relations/anchor.rb', line 14 def modified_rel "#{node.attr("rel")} nofollow noopener noreferrer".strip end |
#safe? ⇒ Boolean
18 19 20 21 22 |
# File 'lib/rack/relations/anchor.rb', line 18 def safe? return true if uri.relative? safelist_domains.any? { |matcher| match?(matcher: matcher, host: uri.host) } end |