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.
48 49 50 51 |
# File 'lib/metapage.rb', line 48 def initialize(url) @url = url title end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
47 48 49 |
# File 'lib/metapage.rb', line 47 def url @url end |
Instance Method Details
#canonical_url ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/metapage.rb', line 89 def canonical_url if image? url else @canonical_url ||= ('og:url') || link_rel('canonical') || url end end |
#content_type ⇒ Object
113 114 115 |
# File 'lib/metapage.rb', line 113 def content_type mimemagic and mimemagic.type end |
#description ⇒ Object
66 67 68 69 70 |
# File 'lib/metapage.rb', line 66 def description unless image? @description ||= ('og:description') || ('description') end end |
#id ⇒ Object
97 98 99 100 101 |
# File 'lib/metapage.rb', line 97 def id if canonical_url @id ||= Digest::SHA1.hexdigest(canonical_url) end end |
#image_url ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/metapage.rb', line 72 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
109 110 111 |
# File 'lib/metapage.rb', line 109 def media_type mimemagic and mimemagic.mediatype end |
#site_name ⇒ Object
103 104 105 106 107 |
# File 'lib/metapage.rb', line 103 def site_name unless image? @site_name ||= ('og:site_name') || host end end |
#title ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/metapage.rb', line 53 def title unless image? @title ||= (('og:title') || html_content('title')).tap do |title| if title checked_title = title.downcase.gsub(' ', '') if IGNORE_LIST.any? {|word| checked_title.include? word } raise IgnoredTitleError end end end end end |
#to_h ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/metapage.rb', line 117 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
131 132 133 |
# File 'lib/metapage.rb', line 131 def to_json to_h.to_json end |
#type ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/metapage.rb', line 81 def type if image? 'image' else @type ||= ('og:type') || 'website' end end |