Class: MetaInspector::Parsers::LinksParser
- Defined in:
- lib/meta_inspector/parsers/links.rb
Instance Method Summary collapse
-
#all ⇒ Object
Returns all links found, unrelavitized and absolutified.
-
#base_href ⇒ Object
Returns the value of the href attribute on the <base /> tag, if exists.
-
#base_url ⇒ Object
Returns the base url to absolutify relative links.
-
#external ⇒ Object
Returns all external HTTP links found.
-
#http ⇒ Object
Returns all HTTP links found.
-
#internal ⇒ Object
Returns all internal HTTP links found.
- #links ⇒ Object
-
#non_http ⇒ Object
Returns all non-HTTP links found.
-
#raw ⇒ Object
Returns all links found, unprocessed.
- #to_hash ⇒ Object
Methods inherited from Base
Constructor Details
This class inherits a constructor from MetaInspector::Parsers::Base
Instance Method Details
#all ⇒ Object
Returns all links found, unrelavitized and absolutified
16 17 18 |
# File 'lib/meta_inspector/parsers/links.rb', line 16 def all @all ||= raw.map { |link| URL.absolutify(link, base_url) }.compact.uniq end |
#base_href ⇒ Object
Returns the value of the href attribute on the <base /> tag, if exists
54 55 56 |
# File 'lib/meta_inspector/parsers/links.rb', line 54 def base_href parsed.search('base').first.attributes['href'].value rescue nil end |
#base_url ⇒ Object
Returns the base url to absolutify relative links. This can be the one set on a <base> tag, or the url of the document if no <base> tag was found.
49 50 51 |
# File 'lib/meta_inspector/parsers/links.rb', line 49 def base_url base_href || url end |
#external ⇒ Object
Returns all external HTTP links found
36 37 38 |
# File 'lib/meta_inspector/parsers/links.rb', line 36 def external @external ||= http.select { |link| URL.new(link).host != host } end |
#http ⇒ Object
Returns all HTTP links found
21 22 23 |
# File 'lib/meta_inspector/parsers/links.rb', line 21 def http @http ||= all.select { |link| link =~ /^http(s)?:\/\//i} end |
#internal ⇒ Object
Returns all internal HTTP links found
31 32 33 |
# File 'lib/meta_inspector/parsers/links.rb', line 31 def internal @internal ||= http.select { |link| URL.new(link).host == host } end |
#links ⇒ Object
6 7 8 |
# File 'lib/meta_inspector/parsers/links.rb', line 6 def links self end |
#non_http ⇒ Object
Returns all non-HTTP links found
26 27 28 |
# File 'lib/meta_inspector/parsers/links.rb', line 26 def non_http @non_http ||= all.select { |link| link !~ /^http(s)?:\/\//i} end |
#raw ⇒ Object
Returns all links found, unprocessed
11 12 13 |
# File 'lib/meta_inspector/parsers/links.rb', line 11 def raw @raw ||= cleanup(parsed.search('//a/@href')).compact.uniq end |
#to_hash ⇒ Object
40 41 42 43 44 |
# File 'lib/meta_inspector/parsers/links.rb', line 40 def to_hash { 'internal' => internal, 'external' => external, 'non_http' => non_http } end |