Class: PageStructuredData::PageTypes::Organization

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

Overview

Organization structured data for a page

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, url:, logo: nil, same_as: [], parent_organization: nil) ⇒ Organization

Returns a new instance of Organization.



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

def initialize(name:, url:, logo: nil, same_as: [], parent_organization: nil)
  @name = name
  @url = url
  @logo = 
  @same_as = same_as
  @parent_organization = parent_organization
end

Instance Attribute Details

#logoObject (readonly)

Returns the value of attribute logo.



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

def 
  @logo
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#parent_organizationObject (readonly)

Returns the value of attribute parent_organization.



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

def parent_organization
  @parent_organization
end

#same_asObject (readonly)

Returns the value of attribute same_as.



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

def same_as
  @same_as
end

#urlObject (readonly)

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#json_ldObject



39
40
41
42
43
44
45
# File 'app/src/page_structured_data/page_types/organization.rb', line 39

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

#to_hObject

rubocop:disable Metrics/MethodLength



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/src/page_structured_data/page_types/organization.rb', line 17

def to_h # rubocop:disable Metrics/MethodLength
  node = {
    '@context': 'https://schema.org',
    '@type': 'Organization',
  }

  node[:name] = name
  node[:url] = url
  node[:logo] =  if .present?
  node[:sameAs] = same_as if same_as.present?

  if parent_organization.present?
    node[:parentOrganization] = {
      '@type': 'Organization',
      name: parent_organization[:name],
      url: parent_organization[:url],
    }
  end

  node
end