Class: PageStructuredData::Breadcrumbs
- Inherits:
-
Object
- Object
- PageStructuredData::Breadcrumbs
- Defined in:
- app/src/page_structured_data/breadcrumbs.rb
Overview
Basic page metadata for any page
Instance Attribute Summary collapse
-
#hierarchy ⇒ Object
readonly
Returns the value of attribute hierarchy.
Instance Method Summary collapse
-
#initialize(hierarchy: []) ⇒ Breadcrumbs
constructor
A new instance of Breadcrumbs.
- #json_ld(current_page_title:) ⇒ Object
- #titles ⇒ Object
-
#to_h(current_page_title:) ⇒ Object
rubocop:disable Metrics/MethodLength.
Constructor Details
#initialize(hierarchy: []) ⇒ Breadcrumbs
Returns a new instance of Breadcrumbs.
8 9 10 |
# File 'app/src/page_structured_data/breadcrumbs.rb', line 8 def initialize(hierarchy: []) @hierarchy = hierarchy end |
Instance Attribute Details
#hierarchy ⇒ Object (readonly)
Returns the value of attribute hierarchy.
6 7 8 |
# File 'app/src/page_structured_data/breadcrumbs.rb', line 6 def hierarchy @hierarchy end |
Instance Method Details
#json_ld(current_page_title:) ⇒ Object
24 25 26 27 28 29 30 |
# File 'app/src/page_structured_data/breadcrumbs.rb', line 24 def json_ld(current_page_title:) %( <script type="application/ld+json"> #{to_h(current_page_title: current_page_title).to_json} </script> ) end |
#titles ⇒ Object
12 13 14 |
# File 'app/src/page_structured_data/breadcrumbs.rb', line 12 def titles hierarchy.pluck(:title) end |
#to_h(current_page_title:) ⇒ Object
rubocop:disable Metrics/MethodLength
16 17 18 19 20 21 22 |
# File 'app/src/page_structured_data/breadcrumbs.rb', line 16 def to_h(current_page_title:) # rubocop:disable Metrics/MethodLength { '@context': 'https://schema.org', '@type': 'BreadcrumbList', 'itemListElement': item_list_elements(current_page_title: current_page_title), } end |