Class: PageStructuredData::PageTypes::NewsArticle
- Inherits:
-
Object
- Object
- PageStructuredData::PageTypes::NewsArticle
- Defined in:
- app/src/page_structured_data/page_types/news_article.rb
Overview
Basic page metadata for any page
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: []) ⇒ NewsArticle
constructor
A new instance of NewsArticle.
-
#json_ld ⇒ Object
rubocop:disable Metrics/MethodLength.
Constructor Details
#initialize(headline:, published_at:, updated_at:, images: [], authors: []) ⇒ NewsArticle
Returns a new instance of NewsArticle.
9 10 11 12 13 14 15 |
# File 'app/src/page_structured_data/page_types/news_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/news_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/news_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/news_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/news_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/news_article.rb', line 7 def updated_at @updated_at end |
Instance Method Details
#json_ld ⇒ Object
rubocop:disable Metrics/MethodLength
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/src/page_structured_data/page_types/news_article.rb', line 17 def json_ld # rubocop:disable Metrics/MethodLength node = { '@context': 'https://schema.org', '@type': 'NewsArticle', } node[:headline] = headline node[:image] = images node[:datePublished] = published_at node[:dateModified] = updated_at = .map do || { '@type': 'Person', name: [:name], url: [:url], } end node[:author] = %( <script type="application/ld+json"> #{node.to_json} </script> ) end |