Class: Rack::Relations::Anchor

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/relations/anchor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nodeObject

Returns the value of attribute node.



6
7
8
# File 'lib/rack/relations/anchor.rb', line 6

def node
  @node
end

#safelist_domainsObject

Returns the value of attribute safelist_domains.



6
7
8
# File 'lib/rack/relations/anchor.rb', line 6

def safelist_domains
  @safelist_domains
end

#uriObject

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_relObject



14
15
16
# File 'lib/rack/relations/anchor.rb', line 14

def modified_rel
  "#{node.attr("rel")} nofollow noopener noreferrer".strip
end

#safe?Boolean

Returns:

  • (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