Class: Metapage::Metadata
- Inherits:
-
Object
- Object
- Metapage::Metadata
- Defined in:
- lib/metapage.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #canonical_url ⇒ Object
- #content_type ⇒ Object
- #description ⇒ Object
- #id ⇒ Object
- #image_url ⇒ Object
-
#initialize(url) ⇒ Metadata
constructor
A new instance of Metadata.
- #media_type ⇒ Object
- #site_name ⇒ Object
- #title ⇒ Object
- #to_h ⇒ Object
- #to_json ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(url) ⇒ Metadata
Returns a new instance of Metadata.
45 46 47 48 |
# File 'lib/metapage.rb', line 45 def initialize(url) @url = url title end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
44 45 46 |
# File 'lib/metapage.rb', line 44 def url @url end |
Instance Method Details
#canonical_url ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/metapage.rb', line 79 def canonical_url if image? url else @canonical_url ||= ('og:url') || link_rel('canonical') || url end end |
#content_type ⇒ Object
103 104 105 |
# File 'lib/metapage.rb', line 103 def content_type mimemagic and mimemagic.type end |
#description ⇒ Object
56 57 58 59 60 |
# File 'lib/metapage.rb', line 56 def description unless image? @description ||= ('og:description') || ('description') end end |
#id ⇒ Object
87 88 89 90 91 |
# File 'lib/metapage.rb', line 87 def id if canonical_url @id ||= Digest::SHA1.hexdigest(canonical_url) end end |
#image_url ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/metapage.rb', line 62 def image_url if image? url else # Fallback to apple-touch-icon, fluid-icon, ms-tileicon etc @image_url ||= ('og:image:secure_url') || ('og:image') || link_rel('apple-touch-icon-precomposed') end end |
#media_type ⇒ Object
99 100 101 |
# File 'lib/metapage.rb', line 99 def media_type mimemagic and mimemagic.mediatype end |
#site_name ⇒ Object
93 94 95 96 97 |
# File 'lib/metapage.rb', line 93 def site_name unless image? @site_name ||= ('og:site_name') || host end end |
#title ⇒ Object
50 51 52 53 54 |
# File 'lib/metapage.rb', line 50 def title unless image? @title ||= ('og:title') || html_content('title') end end |
#to_h ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/metapage.rb', line 107 def to_h { id: id, title: title, description: description, image_url: image_url, type: type, canonical_url: canonical_url, site_name: site_name, media_type: media_type, content_type: content_type } end |
#to_json ⇒ Object
121 122 123 |
# File 'lib/metapage.rb', line 121 def to_json to_h.to_json end |
#type ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/metapage.rb', line 71 def type if image? 'image' else @type ||= ('og:type') || 'website' end end |