Class: MetatagCop::Parser
- Inherits:
-
Object
- Object
- MetatagCop::Parser
- Defined in:
- lib/metatag_cop/parser.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
Returns the value of attribute document.
Instance Method Summary collapse
- #description ⇒ Object
- #h1 ⇒ Object
-
#initialize(url) ⇒ Parser
constructor
A new instance of Parser.
- #keywords ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(url) ⇒ Parser
Returns a new instance of Parser.
12 13 14 |
# File 'lib/metatag_cop/parser.rb', line 12 def initialize(url) @document = parse(url) end |
Instance Attribute Details
#document ⇒ Object
Returns the value of attribute document.
10 11 12 |
# File 'lib/metatag_cop/parser.rb', line 10 def document @document end |
Instance Method Details
#description ⇒ Object
20 21 22 23 |
# File 'lib/metatag_cop/parser.rb', line 20 def description description = document.at('meta[name=description]') description['content'] unless description.nil? end |
#h1 ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/metatag_cop/parser.rb', line 30 def h1 h1 = document.at('h1') return if h1.nil? return h1['content'] unless h1['content'].nil? # it regards alt as h1 content if h1 content is blank. a = find_tag_by(h1, 'a') img = find_tag_by(a, 'img') img.attributes['alt'].value end |
#keywords ⇒ Object
25 26 27 28 |
# File 'lib/metatag_cop/parser.rb', line 25 def keywords keywords = document.at('meta[name=keywords]') keywords['content'] unless keywords.nil? end |
#title ⇒ Object
16 17 18 |
# File 'lib/metatag_cop/parser.rb', line 16 def title document.css('head title').inner_text end |