Class: Termium::LanguageModule

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/termium/language_module.rb

Overview

For

Constant Summary collapse

LANGUAGE_CODE_MAPPING =
{
  "en" => "eng",
  "fr" => "fre",
}.freeze

Instance Method Summary collapse

Instance Method Details

#abbreviationsObject



37
38
39
# File 'lib/termium/language_module.rb', line 37

def abbreviations
  entry_term.map(&:abbreviation).flatten
end

#definitionObject



21
22
23
# File 'lib/termium/language_module.rb', line 21

def definition
  definition_raw&.value_typed
end

#definition_rawObject



17
18
19
# File 'lib/termium/language_module.rb', line 17

def definition_raw
  textual_support.detect(&:is_definition?)
end

#designationsObject



46
47
48
49
# File 'lib/termium/language_module.rb', line 46

def designations
  # NOTE: entry_term is a collection
  entry_term + abbreviations
end

#domainObject



25
26
27
# File 'lib/termium/language_module.rb', line 25

def domain
  definition_raw&.domain
end

#examplesObject



33
34
35
# File 'lib/termium/language_module.rb', line 33

def examples
  textual_support.select(&:is_example?).map(&:value_typed)
end

#notesObject



29
30
31
# File 'lib/termium/language_module.rb', line 29

def notes
  textual_support.select(&:is_note?).map(&:value_typed)
end

#to_concept(options = {}) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/termium/language_module.rb', line 69

def to_concept(options = {})
  x = to_h
  return nil unless x

  Glossarist::LocalizedConcept.new(x).tap do |concept|
    # Fill in register parameters
    if options[:date_accepted]
      # puts options[:date_accepted].inspect
      concept.date_accepted = options[:date_accepted]
    end

    # puts concept.inspect
  end
end

#to_hObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/termium/language_module.rb', line 51

def to_h
  # TODO: This is needed to skip the empty french entries of 10031781 and 10031778
  return nil unless definition

  src = {
    "language_code" => LANGUAGE_CODE_MAPPING[language.downcase],
    "terms" => designations.map(&:to_h),
    "definition" => [{ content: definition }],
    "notes" => notes,
    "examples" => examples,
    "entry_status" => "valid",
  }

  src["domain"] = domain if domain

  src
end