Class: PageStructuredData::PageTypes::WebSite

Inherits:
Object
  • Object
show all
Includes:
SchemaNode
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.



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

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.



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

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#potential_actionObject (readonly)

Returns the value of attribute potential_action.



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

def potential_action
  @potential_action
end

#publisherObject (readonly)

Returns the value of attribute publisher.



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

def publisher
  @publisher
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#json_ldObject



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

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

#to_hObject



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

def to_h
  compact_node(
    '@context': 'https://schema.org',
    '@type': 'WebSite',
    name: name,
    url: url,
    description: description,
    publisher: object_to_h(publisher),
    potentialAction: object_to_h(potential_action)
  )
end