Class: Glossarist::Section

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_file(path) ⇒ Object



33
34
35
36
37
# File 'lib/glossarist/section.rb', line 33

def self.from_file(path)
  return nil unless File.exist?(path)

  from_yaml(File.read(path, encoding: "utf-8"))
end

Instance Method Details

#descendant_by_id(target_id) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/glossarist/section.rb', line 23

def descendant_by_id(target_id)
  children&.each do |child|
    return child if child.id == target_id

    found = child.descendant_by_id(target_id)
    return found if found
  end
  nil
end

#name(lang = nil) ⇒ Object



17
18
19
20
21
# File 'lib/glossarist/section.rb', line 17

def name(lang = nil)
  return names&.dig("eng") if lang.nil?

  names&.dig(lang) || names&.dig("eng")
end