Class: PageStructuredData::PageTypes::WebSite

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

Overview

WebSite structured data for a page

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, url:, description: nil, publisher: nil, potential_action: nil) ⇒ WebSite

Returns a new instance of WebSite.



9
10
11
12
13
14
15
# File 'app/src/page_structured_data/page_types/web_site.rb', line 9

def initialize(name:, url:, description: nil, publisher: nil, potential_action: nil)
  @name = name
  @url = url
  @description = description
  @publisher = publisher
  @potential_action = potential_action
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



7
8
9
# File 'app/src/page_structured_data/page_types/web_site.rb', line 7

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'app/src/page_structured_data/page_types/web_site.rb', line 7

def name
  @name
end

#potential_actionObject (readonly)

Returns the value of attribute potential_action.



7
8
9
# File 'app/src/page_structured_data/page_types/web_site.rb', line 7

def potential_action
  @potential_action
end

#publisherObject (readonly)

Returns the value of attribute publisher.



7
8
9
# File 'app/src/page_structured_data/page_types/web_site.rb', line 7

def publisher
  @publisher
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'app/src/page_structured_data/page_types/web_site.rb', line 7

def url
  @url
end

Instance Method Details

#json_ldObject



32
33
34
35
36
37
38
# File 'app/src/page_structured_data/page_types/web_site.rb', line 32

def json_ld
  %(
  <script type="application/ld+json">
    #{to_h.to_json}
    </script>
  )
end

#to_hObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/src/page_structured_data/page_types/web_site.rb', line 17

def to_h
  node = {
    '@context': 'https://schema.org',
    '@type': 'WebSite',
    name: name,
    url: url,
  }

  node[:description] = description if description.present?
  node[:publisher] = publisher_to_h if publisher.present?
  node[:potentialAction] = potential_action if potential_action.present?

  node
end