Class: PageStructuredData::Page

Inherits:
Object
  • Object
show all
Defined in:
app/src/page_structured_data/page.rb

Overview

Basic page metadata for any page

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title:, description: nil, image: nil, extra_title: '', breadcrumb: nil, page_type: nil) ⇒ Page

rubocop:disable Metrics/ParameterLists



8
9
10
11
12
13
14
15
16
17
18
# File 'app/src/page_structured_data/page.rb', line 8

def initialize(title:, description: nil, image: nil, # rubocop:disable Metrics/ParameterLists
               extra_title: '', breadcrumb: nil, page_type: nil)
  @title = title
  @description = description
  @image = image
  @extra_title = extra_title
  @breadcrumb = breadcrumb
  @page_type = page_type

  @breadcrumb = Breadcrumbs.new if breadcrumb.blank?
end

Instance Attribute Details

Returns the value of attribute breadcrumb.



6
7
8
# File 'app/src/page_structured_data/page.rb', line 6

def breadcrumb
  @breadcrumb
end

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'app/src/page_structured_data/page.rb', line 6

def description
  @description
end

#extra_titleObject (readonly)

Returns the value of attribute extra_title.



6
7
8
# File 'app/src/page_structured_data/page.rb', line 6

def extra_title
  @extra_title
end

#imageObject (readonly)

Returns the value of attribute image.



6
7
8
# File 'app/src/page_structured_data/page.rb', line 6

def image
  @image
end

#page_typeObject (readonly)

Returns the value of attribute page_type.



6
7
8
# File 'app/src/page_structured_data/page.rb', line 6

def page_type
  @page_type
end

#titleObject (readonly)

Returns the value of attribute title.



6
7
8
# File 'app/src/page_structured_data/page.rb', line 6

def title
  @title
end

Instance Method Details

#json_ldsObject



34
35
36
37
38
39
# File 'app/src/page_structured_data/page.rb', line 34

def json_lds
  output = []
  output << breadcrumb.json_ld(current_page_title: title) if breadcrumb.present?
  output << page_type.json_ld if page_type.present?
  output.join
end

#page_titleObject



26
27
28
29
30
31
32
# File 'app/src/page_structured_data/page.rb', line 26

def page_title
  result = title_with_hierarchies.join(separator)
  if base_app_name.present?
    result += separator + base_app_name
  end
  result
end

#title_with_hierarchiesObject



20
21
22
23
24
# File 'app/src/page_structured_data/page.rb', line 20

def title_with_hierarchies
  current_page = extra_title.present? ? [title, extra_title] : [title]
  current_page += breadcrumb.titles.reverse if breadcrumb.present?
  current_page
end