Class: MetaInspector::Parsers::TextsParser
- Defined in:
- lib/meta_inspector/parsers/texts.rb
Instance Method Summary collapse
- #best_title ⇒ Object
-
#description ⇒ Object
A description getter that first checks for a meta description and if not present will guess by looking at the first paragraph with more than 120 characters.
-
#title ⇒ Object
Returns the parsed document title, from the content of the <title> tag within the <head> section.
Methods inherited from Base
Constructor Details
This class inherits a constructor from MetaInspector::Parsers::Base
Instance Method Details
#best_title ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/meta_inspector/parsers/texts.rb', line 12 def best_title @best_title ||= begin candidates = [ parsed.css('head title'), parsed.css('body title'), ['og:title'], parsed.css('h1').first ] candidates.flatten! candidates.map! { |c| (c.respond_to? :inner_text) ? c.inner_text : c } candidates.compact! return nil if candidates.empty? candidates.map! { |c| c.gsub(/\s+/, ' ') } candidates.uniq! candidates.sort_by! { |t| -t.length } candidates.first.strip end end |
#description ⇒ Object
A description getter that first checks for a meta description and if not present will guess by looking at the first paragraph with more than 120 characters
34 35 36 |
# File 'lib/meta_inspector/parsers/texts.rb', line 34 def description ['description'] || secondary_description end |
#title ⇒ Object
Returns the parsed document title, from the content of the <title> tag within the <head> section.
8 9 10 |
# File 'lib/meta_inspector/parsers/texts.rb', line 8 def title @title ||= parsed.css('head title').inner_text rescue nil end |