Class: MetaInfo::Document
- Inherits:
-
Object
- Object
- MetaInfo::Document
- Defined in:
- lib/meta_info/document.rb
Instance Method Summary collapse
- #description ⇒ Object
- #doc ⇒ Object
- #get_attr(name) ⇒ Object
- #image ⇒ Object
-
#initialize(html) ⇒ Document
constructor
A new instance of Document.
- #meta_description ⇒ Object
- #meta_title ⇒ Object
- #og_attr(name) ⇒ Object
- #search_meta(attribute, regexp, value_key) ⇒ Object
- #title ⇒ Object
- #twitter_attr(name) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
Instance Method Details
#description ⇒ Object
18 19 20 |
# File 'lib/meta_info/document.rb', line 18 def description get_attr("description") || end |
#doc ⇒ Object
10 11 12 |
# File 'lib/meta_info/document.rb', line 10 def doc @doc end |
#get_attr(name) ⇒ Object
50 51 52 |
# File 'lib/meta_info/document.rb', line 50 def get_attr(name) og_attr(name) || twitter_attr(name) end |
#image ⇒ Object
22 23 24 |
# File 'lib/meta_info/document.rb', line 22 def image get_attr("image") end |
#meta_description ⇒ Object
30 31 32 |
# File 'lib/meta_info/document.rb', line 30 def ("name", /^description$/i, "content") end |
#meta_title ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/meta_info/document.rb', line 42 def if doc.css("title").empty? return false else return doc.css("title")[0].text end end |
#og_attr(name) ⇒ Object
38 39 40 |
# File 'lib/meta_info/document.rb', line 38 def og_attr(name) ('property', /^og:#{name}$/i, 'content') end |
#search_meta(attribute, regexp, value_key) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/meta_info/document.rb', line 54 def (attribute, regexp, value_key) doc.css('meta').each do |m| if m.attribute(attribute) && m.attribute(attribute).to_s.match(regexp) return m.attribute(value_key).to_s end end return false end |
#title ⇒ Object
14 15 16 |
# File 'lib/meta_info/document.rb', line 14 def title get_attr("title") || end |
#twitter_attr(name) ⇒ Object
34 35 36 |
# File 'lib/meta_info/document.rb', line 34 def twitter_attr(name) ('name', /^twitter:#{name}$/i, 'content') end |
#valid? ⇒ Boolean
26 27 28 |
# File 'lib/meta_info/document.rb', line 26 def valid? title && description != false end |