Class: PageStructuredData::PageTypes::Article
- Inherits:
-
Object
- Object
- PageStructuredData::PageTypes::Article
- Defined in:
- app/src/page_structured_data/page_types/article.rb
Overview
Shared structured data for schema.org article-like page types.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#authors ⇒ Object
readonly
Returns the value of attribute authors.
-
#headline ⇒ Object
readonly
Returns the value of attribute headline.
-
#images ⇒ Object
readonly
Returns the value of attribute images.
-
#published_at ⇒ Object
readonly
Returns the value of attribute published_at.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Instance Method Summary collapse
-
#initialize(headline:, published_at:, updated_at:, images: [], authors: []) ⇒ Article
constructor
A new instance of Article.
- #json_ld ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(headline:, published_at:, updated_at:, images: [], authors: []) ⇒ Article
Returns a new instance of Article.
9 10 11 12 13 14 15 |
# File 'app/src/page_structured_data/page_types/article.rb', line 9 def initialize(headline:, published_at:, updated_at:, images: [], authors: []) @headline = headline @images = images @published_at = published_at @updated_at = updated_at @authors = end |
Instance Attribute Details
#authors ⇒ Object (readonly)
Returns the value of attribute authors.
7 8 9 |
# File 'app/src/page_structured_data/page_types/article.rb', line 7 def @authors end |
#headline ⇒ Object (readonly)
Returns the value of attribute headline.
7 8 9 |
# File 'app/src/page_structured_data/page_types/article.rb', line 7 def headline @headline end |
#images ⇒ Object (readonly)
Returns the value of attribute images.
7 8 9 |
# File 'app/src/page_structured_data/page_types/article.rb', line 7 def images @images end |
#published_at ⇒ Object (readonly)
Returns the value of attribute published_at.
7 8 9 |
# File 'app/src/page_structured_data/page_types/article.rb', line 7 def published_at @published_at end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
7 8 9 |
# File 'app/src/page_structured_data/page_types/article.rb', line 7 def updated_at @updated_at end |
Instance Method Details
#json_ld ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/src/page_structured_data/page_types/article.rb', line 35 def json_ld %( <script type="application/ld+json"> #{to_h.to_json} </script> ) end |
#to_h ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/src/page_structured_data/page_types/article.rb', line 17 def to_h { '@context': 'https://schema.org', '@type': schema_type, headline: headline, image: images, datePublished: published_at, dateModified: updated_at, author: .map do || { '@type': 'Person', name: [:name], url: [:url], } end, } end |