Class: WebAuthor::LdAuthor

Inherits:
T::Struct
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/web_author/ld_author.rb

Constant Summary collapse

ATTRIBUTES =
T.let(['@type', 'name', 'url'].freeze, T::Array[String])

Class Method Summary collapse

Class Method Details

.from_hash(hash) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/web_author/ld_author.rb', line 16

def self.from_hash(hash)
  return new(name: hash) if hash.is_a?(String)

  main_properties = hash.dup.select { |key, _| ATTRIBUTES.include?(key) }
  main_properties['type'] = main_properties.delete('@type')
  main_properties.transform_keys!(&:to_sym)

  additional_properties = hash.dup
  ATTRIBUTES.each { |it| additional_properties.delete(it) }
  additional_properties.transform_keys!(&:to_s)

  new(**main_properties, additional_properties:)
end