Class: PageStructuredData::PageTypes::Organization
- Inherits:
-
Object
- Object
- PageStructuredData::PageTypes::Organization
- Defined in:
- app/src/page_structured_data/page_types/organization.rb
Overview
Organization structured data for a page
Instance Attribute Summary collapse
-
#logo ⇒ Object
readonly
Returns the value of attribute logo.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent_organization ⇒ Object
readonly
Returns the value of attribute parent_organization.
-
#same_as ⇒ Object
readonly
Returns the value of attribute same_as.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(name:, url:, logo: nil, same_as: [], parent_organization: nil) ⇒ Organization
constructor
A new instance of Organization.
- #json_ld ⇒ Object
-
#to_h ⇒ Object
rubocop:disable Metrics/MethodLength.
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 = logo @same_as = same_as @parent_organization = parent_organization end |
Instance Attribute Details
#logo ⇒ Object (readonly)
Returns the value of attribute logo.
7 8 9 |
# File 'app/src/page_structured_data/page_types/organization.rb', line 7 def logo @logo end |
#name ⇒ Object (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_organization ⇒ Object (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_as ⇒ Object (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 |
#url ⇒ Object (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_ld ⇒ Object
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_h ⇒ Object
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] = logo if logo.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 |