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.
-
#article_section ⇒ Object
readonly
Returns the value of attribute article_section.
-
#authors ⇒ Object
readonly
Returns the value of attribute authors.
-
#comments_count ⇒ Object
readonly
Returns the value of attribute comments_count.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#headline ⇒ Object
readonly
Returns the value of attribute headline.
-
#images ⇒ Object
readonly
Returns the value of attribute images.
-
#in_language ⇒ Object
readonly
Returns the value of attribute in_language.
-
#interaction_statistics ⇒ Object
readonly
Returns the value of attribute interaction_statistics.
-
#keywords ⇒ Object
readonly
Returns the value of attribute keywords.
-
#likes_count ⇒ Object
readonly
Returns the value of attribute likes_count.
-
#main_entity_of_page ⇒ Object
readonly
Returns the value of attribute main_entity_of_page.
-
#published_at ⇒ Object
readonly
Returns the value of attribute published_at.
-
#publisher ⇒ Object
readonly
Returns the value of attribute publisher.
-
#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.
-
#word_count ⇒ Object
readonly
Returns the value of attribute word_count.
Instance Method Summary collapse
-
#initialize(headline:, published_at:, updated_at:, images: [], authors: [], image: nil, article_body: nil, text: nil, description: nil, url: nil, main_entity_of_page: nil, publisher: nil, article_section: nil, keywords: nil, word_count: nil, in_language: 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
- #warnings ⇒ Object
Methods included from SchemaNode
Constructor Details
#initialize(headline:, published_at:, updated_at:, images: [], authors: [], image: nil, article_body: nil, text: nil, description: nil, url: nil, main_entity_of_page: nil, publisher: nil, article_section: nil, keywords: nil, word_count: nil, in_language: nil, interaction_statistics: [], likes_count: nil, comments_count: nil, shares_count: nil) ⇒ Article
Returns a new instance of Article.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/src/page_structured_data/page_types/article.rb', line 13 def initialize(headline:, published_at:, updated_at:, images: [], authors: [], image: nil, article_body: nil, text: nil, description: nil, url: nil, main_entity_of_page: nil, publisher: nil, article_section: nil, keywords: nil, word_count: nil, in_language: 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() @description = description @article_body = article_body || text @url = url @main_entity_of_page = main_entity_of_page @publisher = publisher @article_section = article_section @keywords = keywords @word_count = word_count @in_language = in_language @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 |
#article_section ⇒ Object (readonly)
Returns the value of attribute article_section.
9 10 11 |
# File 'app/src/page_structured_data/page_types/article.rb', line 9 def article_section @article_section 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 |
#description ⇒ Object (readonly)
Returns the value of attribute description.
9 10 11 |
# File 'app/src/page_structured_data/page_types/article.rb', line 9 def description @description 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 |
#in_language ⇒ Object (readonly)
Returns the value of attribute in_language.
9 10 11 |
# File 'app/src/page_structured_data/page_types/article.rb', line 9 def in_language @in_language 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 |
#keywords ⇒ Object (readonly)
Returns the value of attribute keywords.
9 10 11 |
# File 'app/src/page_structured_data/page_types/article.rb', line 9 def keywords @keywords 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 |
#main_entity_of_page ⇒ Object (readonly)
Returns the value of attribute main_entity_of_page.
9 10 11 |
# File 'app/src/page_structured_data/page_types/article.rb', line 9 def main_entity_of_page @main_entity_of_page 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 |
#publisher ⇒ Object (readonly)
Returns the value of attribute publisher.
9 10 11 |
# File 'app/src/page_structured_data/page_types/article.rb', line 9 def publisher @publisher 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 |
#word_count ⇒ Object (readonly)
Returns the value of attribute word_count.
9 10 11 |
# File 'app/src/page_structured_data/page_types/article.rb', line 9 def word_count @word_count end |
Instance Method Details
#json_ld ⇒ Object
62 63 64 65 66 67 68 |
# File 'app/src/page_structured_data/page_types/article.rb', line 62 def json_ld %( <script type="application/ld+json"> #{to_h.to_json} </script> ) end |
#to_h ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/src/page_structured_data/page_types/article.rb', line 37 def to_h node = { '@context': 'https://schema.org', '@type': schema_type, headline: headline, image: images, datePublished: published_at, dateModified: updated_at, author: .map { || () }, } node[:description] = description if description.present? node[:articleBody] = article_body if article_body.present? node[:url] = url if url.present? node[:mainEntityOfPage] = object_to_h(main_entity_of_page) if main_entity_of_page.present? node[:publisher] = object_to_h(publisher) if publisher.present? node[:articleSection] = article_section if article_section.present? node[:keywords] = keywords if keywords.present? node[:wordCount] = word_count if word_count.present? node[:inLanguage] = object_to_h(in_language) if in_language.present? node[:interactionStatistic] = interaction_statistics_to_h if interaction_statistics_to_h.any? node end |
#warnings ⇒ Object
70 71 72 73 74 75 76 |
# File 'app/src/page_structured_data/page_types/article.rb', line 70 def warnings required_attribute_warnings( headline: headline, published_at: published_at, updated_at: updated_at ) + + publisher_warnings + interaction_statistic_warnings end |