Class: PageStructuredData::PageTypes::Article
- Inherits:
-
Object
- Object
- PageStructuredData::PageTypes::Article
- Includes:
- SchemaNode
- 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
-
#article_body ⇒ Object
readonly
Returns the value of attribute article_body.
-
#authors ⇒ Object
readonly
Returns the value of attribute authors.
-
#comments_count ⇒ Object
readonly
Returns the value of attribute comments_count.
-
#headline ⇒ Object
readonly
Returns the value of attribute headline.
-
#images ⇒ Object
readonly
Returns the value of attribute images.
-
#interaction_statistics ⇒ Object
readonly
Returns the value of attribute interaction_statistics.
-
#likes_count ⇒ Object
readonly
Returns the value of attribute likes_count.
-
#published_at ⇒ Object
readonly
Returns the value of attribute published_at.
-
#shares_count ⇒ Object
readonly
Returns the value of attribute shares_count.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(headline:, published_at:, updated_at:, images: [], authors: [], image: nil, article_body: nil, text: nil, url: nil, interaction_statistics: [], likes_count: nil, comments_count: nil, shares_count: nil) ⇒ Article
constructor
A new instance of Article.
- #json_ld ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(headline:, published_at:, updated_at:, images: [], authors: [], image: nil, article_body: nil, text: nil, url: nil, interaction_statistics: [], likes_count: nil, comments_count: nil, shares_count: nil) ⇒ Article
Returns a new instance of Article.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/src/page_structured_data/page_types/article.rb', line 12 def initialize(headline:, published_at:, updated_at:, images: [], authors: [], image: nil, article_body: nil, text: nil, url: nil, interaction_statistics: [], likes_count: nil, comments_count: nil, shares_count: nil) @headline = headline @images = image.present? ? Array(image) : Array(images) @published_at = published_at @updated_at = updated_at @authors = Array() @article_body = article_body || text @url = url @interaction_statistics = Array(interaction_statistics) @likes_count = likes_count @comments_count = comments_count @shares_count = shares_count end |
Instance Attribute Details
#article_body ⇒ Object (readonly)
Returns the value of attribute article_body.
9 10 11 |
# File 'app/src/page_structured_data/page_types/article.rb', line 9 def article_body @article_body end |
#authors ⇒ Object (readonly)
Returns the value of attribute authors.
9 10 11 |
# File 'app/src/page_structured_data/page_types/article.rb', line 9 def @authors end |
#comments_count ⇒ Object (readonly)
Returns the value of attribute comments_count.
9 10 11 |
# File 'app/src/page_structured_data/page_types/article.rb', line 9 def comments_count @comments_count end |
#headline ⇒ Object (readonly)
Returns the value of attribute headline.
9 10 11 |
# File 'app/src/page_structured_data/page_types/article.rb', line 9 def headline @headline end |
#images ⇒ Object (readonly)
Returns the value of attribute images.
9 10 11 |
# File 'app/src/page_structured_data/page_types/article.rb', line 9 def images @images end |
#interaction_statistics ⇒ Object (readonly)
Returns the value of attribute interaction_statistics.
9 10 11 |
# File 'app/src/page_structured_data/page_types/article.rb', line 9 def interaction_statistics @interaction_statistics end |
#likes_count ⇒ Object (readonly)
Returns the value of attribute likes_count.
9 10 11 |
# File 'app/src/page_structured_data/page_types/article.rb', line 9 def likes_count @likes_count end |
#published_at ⇒ Object (readonly)
Returns the value of attribute published_at.
9 10 11 |
# File 'app/src/page_structured_data/page_types/article.rb', line 9 def published_at @published_at end |
#shares_count ⇒ Object (readonly)
Returns the value of attribute shares_count.
9 10 11 |
# File 'app/src/page_structured_data/page_types/article.rb', line 9 def shares_count @shares_count end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
9 10 11 |
# File 'app/src/page_structured_data/page_types/article.rb', line 9 def updated_at @updated_at end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
9 10 11 |
# File 'app/src/page_structured_data/page_types/article.rb', line 9 def url @url end |
Instance Method Details
#json_ld ⇒ Object
45 46 47 48 49 50 51 |
# File 'app/src/page_structured_data/page_types/article.rb', line 45 def json_ld %( <script type="application/ld+json"> #{to_h.to_json} </script> ) end |
#to_h ⇒ Object
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/article.rb', line 27 def to_h node = { '@context': 'https://schema.org', '@type': schema_type, headline: headline, image: images, datePublished: published_at, dateModified: updated_at, author: .map { || () }, } node[:articleBody] = article_body if article_body.present? node[:url] = url if url.present? node[:interactionStatistic] = interaction_statistics_to_h if interaction_statistics_to_h.any? node end |