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, social_description: nil, image: nil, extra_title: '', breadcrumb: nil, page_type: nil, page_types: nil, canonical_url: nil, fallback_image: nil, base_app_name: nil, render_breadcrumb_json_ld: nil, robots: nil) ⇒ Page

rubocop:disable Metrics/ParameterLists



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/src/page_structured_data/page.rb', line 9

def initialize(title:, description: nil, social_description: nil, image: nil, # rubocop:disable Metrics/ParameterLists
               extra_title: '', breadcrumb: nil, page_type: nil, page_types: nil, canonical_url: nil,
               fallback_image: nil, base_app_name: nil, render_breadcrumb_json_ld: nil, robots: nil)
  @title = title
  @description = description
  @social_description = social_description
  @image = image
  @extra_title = extra_title
  @breadcrumb = breadcrumb
  @page_type = page_type
  @page_types = page_types
  @canonical_url = canonical_url
  @fallback_image = fallback_image
  @base_app_name = base_app_name
  @render_breadcrumb_json_ld = render_breadcrumb_json_ld
  @robots = robots
end

Instance Attribute Details

#base_app_nameObject (readonly)

Returns the value of attribute base_app_name.



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

def base_app_name
  @base_app_name
end

Returns the value of attribute breadcrumb.



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

def breadcrumb
  @breadcrumb
end

#canonical_urlObject (readonly)

Returns the value of attribute canonical_url.



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

def canonical_url
  @canonical_url
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

#fallback_imageObject (readonly)

Returns the value of attribute fallback_image.



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

def fallback_image
  @fallback_image
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

#page_typesObject (readonly)

Returns the value of attribute page_types.



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

def page_types
  @page_types
end

#render_breadcrumb_json_ldObject (readonly)

Returns the value of attribute render_breadcrumb_json_ld.



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

def render_breadcrumb_json_ld
  @render_breadcrumb_json_ld
end

#robotsObject (readonly)

Returns the value of attribute robots.



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

def robots
  @robots
end

#social_descriptionObject (readonly)

Returns the value of attribute social_description.



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

def social_description
  @social_description
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



41
42
43
44
45
46
# File 'app/src/page_structured_data/page.rb', line 41

def json_lds
  output = []
  output << breadcrumb_json_ld if (breadcrumb_json_ld = self.breadcrumb_json_ld).present?
  resolved_page_types.each { |resolved_page_type| output << resolved_page_type.json_ld }
  output.join
end

#page_titleObject



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

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

#resolved_imageObject



48
49
50
# File 'app/src/page_structured_data/page.rb', line 48

def resolved_image
  image || fallback_image
end

#resolved_social_descriptionObject



52
53
54
# File 'app/src/page_structured_data/page.rb', line 52

def resolved_social_description
  social_description.presence || description
end

#robots_contentObject



56
57
58
# File 'app/src/page_structured_data/page.rb', line 56

def robots_content
  Array(robots).compact.join(',')
end

#title_with_hierarchiesObject



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

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

#valid?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'app/src/page_structured_data/page.rb', line 64

def valid?
  warnings.empty?
end

#warningsObject



60
61
62
# File 'app/src/page_structured_data/page.rb', line 60

def warnings
  page_warnings + page_type_warnings
end