Class: Glossarist::Designation::Base

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/glossarist/designation/base.rb

Direct Known Subclasses

Expression, Symbol

Class Method Summary collapse

Class Method Details

.infer_designation_type(hash) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/glossarist/designation/base.rb', line 36

def self.infer_designation_type(hash)
  if hash["international"] || hash["abbreviation_type"]
    "symbol"
  else
    "expression"
  end
end

.of_yaml(hash, options = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/glossarist/designation/base.rb', line 17

def self.of_yaml(hash, options = {})
  type = hash["type"]

  if type.nil? || /\w/ !~ type
    type = infer_designation_type(hash)
    hash["type"] = type
  end

  if self == Base
    SERIALIZED_TYPES[type].of_yaml(hash)
  else
    unless SERIALIZED_TYPES[self] == type
      raise ArgumentError, "unexpected designation type: #{type}"
    end

    super
  end
end