glossarist 2.3.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/.rubocop_todo.yml +65 -0
  4. data/README.adoc +2 -2
  5. data/config.yml +1 -1
  6. data/glossarist.gemspec +1 -0
  7. data/lib/glossarist/asset.rb +4 -9
  8. data/lib/glossarist/citation.rb +73 -41
  9. data/lib/glossarist/collection.rb +2 -11
  10. data/lib/glossarist/collections/asset_collection.rb +0 -3
  11. data/lib/glossarist/collections/bibliography_collection.rb +1 -1
  12. data/lib/glossarist/concept.rb +67 -206
  13. data/lib/glossarist/concept_data.rb +66 -0
  14. data/lib/glossarist/concept_date.rb +7 -11
  15. data/lib/glossarist/concept_manager.rb +19 -29
  16. data/lib/glossarist/concept_set.rb +6 -4
  17. data/lib/glossarist/concept_source.rb +15 -58
  18. data/lib/glossarist/config.rb +4 -4
  19. data/lib/glossarist/designation/abbreviation.rb +15 -16
  20. data/lib/glossarist/designation/base.rb +16 -15
  21. data/lib/glossarist/designation/expression.rb +18 -26
  22. data/lib/glossarist/designation/grammar_info.rb +29 -45
  23. data/lib/glossarist/designation/graphical_symbol.rb +12 -8
  24. data/lib/glossarist/designation/letter_symbol.rb +13 -11
  25. data/lib/glossarist/designation/symbol.rb +11 -13
  26. data/lib/glossarist/designation.rb +3 -3
  27. data/lib/glossarist/detailed_definition.rb +6 -24
  28. data/lib/glossarist/error.rb +4 -4
  29. data/lib/glossarist/glossary_definition.rb +6 -3
  30. data/lib/glossarist/localized_concept.rb +17 -62
  31. data/lib/glossarist/managed_concept.rb +74 -146
  32. data/lib/glossarist/managed_concept_collection.rb +15 -24
  33. data/lib/glossarist/managed_concept_data.rb +47 -0
  34. data/lib/glossarist/non_verb_rep.rb +10 -13
  35. data/lib/glossarist/related_concept.rb +14 -21
  36. data/lib/glossarist/utilities/uuid.rb +10 -5
  37. data/lib/glossarist/utilities.rb +0 -2
  38. data/lib/glossarist/version.rb +1 -1
  39. data/lib/glossarist.rb +10 -9
  40. metadata +23 -13
  41. data/lib/glossarist/model.rb +0 -40
  42. data/lib/glossarist/utilities/boolean_attributes.rb +0 -35
  43. data/lib/glossarist/utilities/enum/class_methods.rb +0 -99
  44. data/lib/glossarist/utilities/enum/enum_collection.rb +0 -45
  45. data/lib/glossarist/utilities/enum/instance_methods.rb +0 -55
  46. data/lib/glossarist/utilities/enum.rb +0 -21
  47. data/lib/glossarist/v1_reader.rb +0 -28
@@ -0,0 +1,66 @@
1
+ module Glossarist
2
+ class ConceptData < Lutaml::Model::Serializable
3
+ include Glossarist::Utilities::CommonFunctions
4
+
5
+ attribute :dates, ConceptDate, collection: true
6
+ attribute :definition, DetailedDefinition, collection: true
7
+ attribute :examples, DetailedDefinition, collection: true
8
+ attribute :id, :string
9
+ attribute :lineage_source_similarity, :integer
10
+ attribute :notes, DetailedDefinition, collection: true
11
+ attribute :release, :string
12
+ attribute :sources, ConceptSource, collection: true
13
+ attribute :terms, Designation::Base, collection: true
14
+ attribute :related, RelatedConcept, collection: true
15
+ attribute :domain, :string
16
+ attribute :review_date, :date_time
17
+ attribute :review_decision_date, :date_time
18
+ attribute :review_decision_event, :string
19
+
20
+ # Concept Methods
21
+ # Language code should be exactly 3 char long.
22
+ # TODO: use min_length, max_length once added in lutaml-model
23
+ attribute :language_code, :string, pattern: /^.{3}$/
24
+ attribute :entry_status, :string
25
+
26
+ yaml do
27
+ map :dates, to: :dates
28
+ map :definition, to: :definition, render_nil: true
29
+ map :examples, to: :examples, render_nil: true
30
+ map :id, to: :id
31
+ map :lineage_source_similarity, to: :lineage_source_similarity
32
+ map :notes, to: :notes, render_nil: true
33
+ map :release, to: :release
34
+ map :sources, to: :sources
35
+ map :terms, to: :terms,
36
+ with: { from: :terms_from_yaml, to: :terms_to_yaml }
37
+ map :related, to: :related
38
+ map :domain, to: :domain
39
+ map :language_code, to: :language_code
40
+ map :entry_status, to: :entry_status
41
+ map :review_date, to: :review_date
42
+ map :review_decision_date, to: :review_decision_date
43
+ map :review_decision_event, to: :review_decision_event
44
+ end
45
+
46
+ def terms_from_yaml(model, value)
47
+ model.terms = value.map { |v| Designation::Base.of_yaml(v) }
48
+ end
49
+
50
+ def terms_to_yaml(model, doc)
51
+ doc["terms"] = model.terms.map(&:to_yaml_hash)
52
+ end
53
+
54
+ def date_accepted
55
+ return nil unless dates
56
+
57
+ dates.find(&:accepted?)
58
+ end
59
+
60
+ def authoritative_source
61
+ return [] unless sources
62
+
63
+ sources.select(&:authoritative?)
64
+ end
65
+ end
66
+ end
@@ -1,20 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Glossarist
4
- class ConceptDate < Model
5
- include Glossarist::Utilities::Enum
6
-
4
+ class ConceptDate < Lutaml::Model::Serializable
7
5
  # Iso8601 date
8
6
  # @return [String]
9
- attr_accessor :date
10
-
11
- register_enum :type, Glossarist::GlossaryDefinition::CONCEPT_DATE_TYPES
7
+ attribute :date, :date_time
8
+ attribute :type, :string,
9
+ values: Glossarist::GlossaryDefinition::CONCEPT_DATE_TYPES
12
10
 
13
- def to_h
14
- {
15
- "date" => date,
16
- "type" => type,
17
- }.compact
11
+ yaml do
12
+ map :date, to: :date
13
+ map :type, to: :type
18
14
  end
19
15
  end
20
16
  end
@@ -1,44 +1,35 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Glossarist
4
- class ConceptManager
5
- # Path to concepts directory.
6
- # @return [String]
7
- attr_accessor :path
8
- attr_accessor :localized_concepts_path
9
-
10
- # @param path [String]
11
- # concepts directory path, either absolute or relative to CWD
12
- def initialize(path: nil)
13
- @path = path
2
+ class ConceptManager < Lutaml::Model::Serializable
3
+ attribute :path, :string
4
+ attribute :localized_concepts_path, :string
5
+
6
+ yaml do
7
+ map :path, to: :path
8
+ map :localized_concepts_path, to: :localized_concepts_path
14
9
  end
15
10
 
16
- # Reads all concepts from files.
17
11
  def load_from_files(collection: nil)
18
12
  collection ||= ManagedConceptCollection.new
19
13
 
20
14
  Dir.glob(concepts_glob) do |filename|
21
- concept = if v1_collection?
22
- Glossarist::V1Reader.load_concept_from_file(filename)
23
- else
24
- load_concept_from_file(filename)
25
- end
15
+ concept = load_concept_from_file(filename)
26
16
 
27
17
  collection.store(concept)
28
18
  end
29
19
  end
30
20
 
31
- # Writes all concepts to files.
32
21
  def save_to_files(managed_concepts)
33
- managed_concepts.each_value &method(:save_concept_to_file)
22
+ managed_concepts.each &method(:save_concept_to_file)
34
23
  end
35
24
 
36
25
  def load_concept_from_file(filename)
37
- concept_hash = Psych.safe_load(File.read(filename), permitted_classes: [Date, Time])
26
+ concept_hash = Psych.safe_load(File.read(filename),
27
+ permitted_classes: [Date, Time])
38
28
  concept_hash["uuid"] = concept_hash["id"] || File.basename(filename, ".*")
39
29
 
40
- concept = Config.class_for(:managed_concept).new(concept_hash)
41
- concept.localized_concepts.each do |_lang, id|
30
+ concept = Config.class_for(:managed_concept).of_yaml(concept_hash)
31
+
32
+ concept.data.localized_concepts.each_value do |id|
42
33
  localized_concept = load_localized_concept(id)
43
34
  concept.add_l10n(localized_concept)
44
35
  end
@@ -55,7 +46,7 @@ module Glossarist
55
46
  )
56
47
  concept_hash["uuid"] = id
57
48
 
58
- Config.class_for(:localized_concept).new(concept_hash)
49
+ Config.class_for(:localized_concept).of_yaml(concept_hash)
59
50
  rescue Psych::SyntaxError => e
60
51
  raise Glossarist::ParseError.new(filename: filename, line: e.line)
61
52
  end
@@ -70,16 +61,14 @@ module Glossarist
70
61
  Dir.mkdir(localized_concept_dir) unless Dir.exist?(localized_concept_dir)
71
62
 
72
63
  filename = File.join(concept_dir, "#{concept.uuid}.yaml")
73
- File.write(filename, Psych.dump(concept.to_h))
64
+ File.write(filename, concept.to_yaml)
74
65
 
75
66
  concept.localized_concepts.each do |lang, uuid|
76
67
  filename = File.join(localized_concept_dir, "#{uuid}.yaml")
77
- File.write(filename, Psych.dump(concept.localization(lang).to_h))
68
+ File.write(filename, concept.localization(lang).to_yaml)
78
69
  end
79
70
  end
80
71
 
81
- private
82
-
83
72
  def concepts_glob
84
73
  if v1_collection?
85
74
  File.join(path, "concept-*.{yaml,yml}")
@@ -116,7 +105,8 @@ module Glossarist
116
105
  end
117
106
 
118
107
  def v1_collection?
119
- @v1_collection ||= !Dir.glob(File.join(path, "concept-*.{yaml,yml}")).empty?
108
+ @v1_collection ||= !Dir.glob(File.join(path,
109
+ "concept-*.{yaml,yml}")).empty?
120
110
  end
121
111
  end
122
112
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "set"
4
+
3
5
  module Glossarist
4
6
  class ConceptSet
5
7
  # a `Glossarist::ManagedConceptCollection` object
@@ -40,7 +42,7 @@ module Glossarist
40
42
  concept = concept_map[concept_name.strip.downcase]
41
43
 
42
44
  if concept.nil?
43
- puts " [Not Found]: #{concept_name.strip}"
45
+ puts " [Not Found]: #{concept_name.strip}"
44
46
  else
45
47
  latex_template(concept)
46
48
  end
@@ -57,7 +59,7 @@ module Glossarist
57
59
 
58
60
  def latex_template(concept)
59
61
  <<~TEMPLATE
60
- \\newglossaryentry{#{concept.default_designation.gsub('_', '-')}}
62
+ \\newglossaryentry{#{concept.default_designation.tr('_', '-')}}
61
63
  {
62
64
  name={#{concept.default_designation.gsub('_', '\_')}}
63
65
  description={#{normalize_definition(concept.default_definition)}}
@@ -66,8 +68,8 @@ module Glossarist
66
68
  end
67
69
 
68
70
  def normalize_definition(definition)
69
- definition.gsub(/{{([^}]*)}}/) do |match|
70
- "\\textbf{\\gls{#{Regexp.last_match[1].gsub('_', '-')}}}"
71
+ definition.gsub(/{{([^}]*)}}/) do |_match|
72
+ "\\textbf{\\gls{#{Regexp.last_match[1].tr('_', '-')}}}"
71
73
  end
72
74
  end
73
75
 
@@ -1,62 +1,19 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Glossarist
4
- class ConceptSource < Model
5
- include Glossarist::Utilities::Enum
6
- include Glossarist::Utilities::CommonFunctions
7
-
8
- register_enum :status, Glossarist::GlossaryDefinition::CONCEPT_SOURCE_STATUSES
9
- register_enum :type, Glossarist::GlossaryDefinition::CONCEPT_SOURCE_TYPES
10
-
11
- attr_reader :origin
12
- alias_method :ref, :origin
13
-
14
- attr_accessor :modification
15
-
16
- def initialize(attributes = {})
17
- if rel = attributes.delete("relationship")
18
- self.status = rel["type"]
19
- self.modification = rel["modification"]
20
- end
21
-
22
- self.origin = slice_keys(attributes, ref_param_names)
23
-
24
- remaining_attributes = attributes.dup
25
- ref_param_names.each { |k| remaining_attributes.delete(k) }
26
-
27
- super(remaining_attributes)
28
- end
29
-
30
- def origin=(origin)
31
- @origin = Citation.new(origin)
32
- end
33
-
34
- alias_method :ref=, :origin=
35
-
36
- def to_h
37
- origin_hash = self.origin.to_h.empty? ? nil : self.origin.to_h
38
-
39
- {
40
- "origin" => origin_hash,
41
- "type" => type.to_s,
42
- "status" => status&.to_s,
43
- "modification" => modification,
44
- }.compact
45
- end
46
-
47
- private
48
-
49
- def ref_param_names
50
- %w[
51
- ref
52
- text
53
- source
54
- id
55
- version
56
- clause
57
- link
58
- original
59
- ]
2
+ class ConceptSource < Lutaml::Model::Serializable
3
+ attribute :status, :string,
4
+ values: Glossarist::GlossaryDefinition::CONCEPT_SOURCE_STATUSES
5
+ attribute :type, :string,
6
+ values: Glossarist::GlossaryDefinition::CONCEPT_SOURCE_TYPES
7
+ attribute :origin, Citation
8
+ attribute :modification, :string
9
+
10
+ yaml do
11
+ # TODO: change to `map [:ref, :origin], to: :origin
12
+ # when multiple key mapping is supported in lutaml-model
13
+ map :origin, to: :origin
14
+ map :status, to: :status
15
+ map :type, to: :type
16
+ map :modification, to: :modification
60
17
  end
61
18
  end
62
19
  end
@@ -42,19 +42,19 @@ module Glossarist
42
42
 
43
43
  class << self
44
44
  def class_for(name)
45
- self.instance.class_for(name)
45
+ instance.class_for(name)
46
46
  end
47
47
 
48
48
  def extension_attributes
49
- self.instance.extension_attributes
49
+ instance.extension_attributes
50
50
  end
51
51
 
52
52
  def register_class(class_name, klass)
53
- self.instance.register_class(class_name, klass)
53
+ instance.register_class(class_name, klass)
54
54
  end
55
55
 
56
56
  def register_extension_attributes(attributes)
57
- self.instance.register_extension_attributes(attributes)
57
+ instance.register_extension_attributes(attributes)
58
58
  end
59
59
  end
60
60
  end
@@ -1,26 +1,25 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "expression"
4
- require_relative "../utilities"
5
-
6
1
  module Glossarist
7
2
  module Designation
8
3
  class Abbreviation < Expression
9
- include Glossarist::Utilities::Enum
10
-
11
- register_enum :type, Glossarist::GlossaryDefinition::ABBREVIATION_TYPES
4
+ attribute :international, :boolean
5
+ attribute :type, :string, default: -> { "abbreviation" }
12
6
 
13
- attr_accessor :international
7
+ Glossarist::GlossaryDefinition::ABBREVIATION_TYPES.each do |name|
8
+ attribute name.to_sym, :boolean
9
+ end
14
10
 
15
- def to_h
16
- type_hash = {
17
- "type" => "abbreviation",
18
- "international" => international,
19
- }
11
+ yaml do
12
+ map :international, to: :international
13
+ map :type, to: :type, render_default: true
14
+ Glossarist::GlossaryDefinition::ABBREVIATION_TYPES.each do |name|
15
+ map name.to_sym, to: name.to_sym
16
+ end
17
+ end
20
18
 
21
- type_hash[type.to_s] = true if type
19
+ def self.of_yaml(hash, options = {})
20
+ hash["type"] = "abbreviation" unless hash["type"]
22
21
 
23
- super().merge(type_hash).compact
22
+ super
24
23
  end
25
24
  end
26
25
  end
@@ -1,35 +1,36 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Glossarist
4
2
  module Designation
5
- class Base < Model
6
- include Glossarist::Utilities::Enum
7
-
8
- # @note This is not entirely aligned with agreed schema and may be
9
- # changed.
10
- attr_accessor :designation
3
+ class Base < Lutaml::Model::Serializable
4
+ attribute :designation, :string
5
+ attribute :geographical_area, :string
6
+ attribute :normative_status, :string,
7
+ values: Glossarist::GlossaryDefinition::DESIGNATION_BASE_NORMATIVE_STATUSES
8
+ attribute :type, :string
11
9
 
12
- attr_accessor :geographical_area
13
- register_enum :normative_status, Glossarist::GlossaryDefinition::DESIGNATION_BASE_NORMATIVE_STATUSES
10
+ yaml do
11
+ map :type, to: :type
12
+ map :normative_status, to: :normative_status
13
+ map :geographical_area, to: :geographical_area
14
+ map :designation, to: :designation
15
+ end
14
16
 
15
- def self.from_h(hash)
17
+ def self.of_yaml(hash, options = {})
16
18
  type = hash["type"]
17
19
 
18
20
  if type.nil? || /\w/ !~ type
19
21
  raise ArgumentError, "designation type is missing"
20
22
  end
21
23
 
22
- designation_subclass = SERIALIZED_TYPES[type]
23
-
24
24
  if self == Base
25
25
  # called on Base class, delegate it to proper subclass
26
- SERIALIZED_TYPES[type].from_h(hash)
26
+ SERIALIZED_TYPES[type].of_yaml(hash)
27
27
  else
28
28
  # called on subclass, instantiate object
29
29
  unless SERIALIZED_TYPES[self] == type
30
30
  raise ArgumentError, "unexpected designation type: #{type}"
31
31
  end
32
- super(hash.reject { |k, _| k == "type" })
32
+
33
+ super(hash, options)
33
34
  end
34
35
  end
35
36
  end
@@ -1,24 +1,26 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative "base"
2
+ require_relative "grammar_info"
4
3
 
5
4
  module Glossarist
6
5
  module Designation
7
6
  class Expression < Base
8
- attr_accessor :prefix
9
- attr_accessor :usage_info
10
-
11
- # List of grammar info.
12
- # @return [Array<GrammarInfo>]
13
- attr_reader :grammar_info
14
-
15
- def grammar_info=(grammar_info)
16
- @grammar_info = grammar_info.map { |g| GrammarInfo.new(g) }
7
+ attribute :prefix, :string
8
+ attribute :usage_info, :string
9
+
10
+ attribute :gender, :string
11
+ attribute :plurality, :string
12
+ attribute :part_of_speech, :string
13
+ attribute :grammar_info, GrammarInfo, collection: true
14
+ attribute :type, :string, default: -> { "expression" }
15
+
16
+ yaml do
17
+ map :type, to: :type, render_default: true
18
+ map :prefix, to: :prefix
19
+ map :usage_info, to: :usage_info
20
+ map :grammar_info, to: :grammar_info
17
21
  end
18
22
 
19
- # @todo Added to cater for current iev-data implementation,
20
- # might be removed in the future.
21
- def self.from_h(hash)
23
+ def self.of_yaml(hash, options = {})
22
24
  gender = hash.delete("gender") || hash.delete(:gender)
23
25
  number = hash.delete("plurality") || hash.delete(:plurality)
24
26
  part_of_speech = hash.delete("part_of_speech") || hash.delete(:part_of_speech)
@@ -31,19 +33,9 @@ module Glossarist
31
33
  }.compact]
32
34
  end
33
35
 
34
- super
35
- end
36
+ hash["type"] = "expression" unless hash["type"]
36
37
 
37
- def to_h
38
- {
39
- "type" => "expression",
40
- "prefix" => prefix,
41
- "normative_status" => normative_status,
42
- "usage_info" => usage_info,
43
- "designation" => designation,
44
- "geographical_area" => geographical_area,
45
- "grammar_info" => grammar_info&.map(&:to_h),
46
- }.compact
38
+ super(hash, options)
47
39
  end
48
40
  end
49
41
  end
@@ -1,57 +1,41 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../utilities"
4
-
5
1
  module Glossarist
6
2
  module Designation
7
- class GrammarInfo
8
- include Glossarist::Utilities::Enum
9
- include Glossarist::Utilities::BooleanAttributes
10
- include Glossarist::Utilities::CommonFunctions
11
-
12
- register_enum :gender, Glossarist::GlossaryDefinition::GRAMMAR_INFO_GENDERS, multiple: true
13
- register_enum :number, Glossarist::GlossaryDefinition::GRAMMAR_INFO_NUMBERS, multiple: true
14
-
15
- register_boolean_attributes Glossarist::GlossaryDefinition::GRAMMAR_INFO_BOOLEAN_ATTRIBUTES
16
-
17
- def initialize(options = {})
18
- sanitized_options(options).each do |attr, value|
19
- public_send("#{attr}=", value)
3
+ class GrammarInfo < Lutaml::Model::Serializable
4
+ attribute :gender, :string,
5
+ values: Glossarist::GlossaryDefinition::GRAMMAR_INFO_GENDERS, collection: true
6
+ attribute :number, :string,
7
+ values: Glossarist::GlossaryDefinition::GRAMMAR_INFO_NUMBERS, collection: true
8
+ attribute :part_of_speech, :string,
9
+ values: Glossarist::GlossaryDefinition::GRAMMAR_INFO_BOOLEAN_ATTRIBUTES
10
+
11
+ yaml do
12
+ map :gender, to: :gender
13
+ map :number, to: :number
14
+
15
+ map :part_of_speech,
16
+ with: { to: :part_of_speech_to_yaml,
17
+ from: :part_of_speech_from_yaml }
18
+ Glossarist::GlossaryDefinition::GRAMMAR_INFO_BOOLEAN_ATTRIBUTES.each do |bool_attr|
19
+ map bool_attr,
20
+ with: { to: :"part_of_speech_#{bool_attr}_to_yaml",
21
+ from: :"part_of_speech_#{bool_attr}_from_yaml" }
20
22
  end
21
23
  end
22
24
 
23
- def part_of_speech=(pos)
24
- public_send("#{pos}=", pos)
25
+ def part_of_speech_from_yaml(model, value)
26
+ model.part_of_speech = value
25
27
  end
26
28
 
27
- def to_h
28
- {
29
- "preposition" => preposition?,
30
- "participle" => participle?,
31
- "adj" => adj?,
32
- "verb" => verb?,
33
- "adverb" => adverb?,
34
- "noun" => noun?,
35
- "gender" => gender,
36
- "number" => number,
37
- }
38
- end
29
+ def part_of_speech_to_yaml(model, doc); end
39
30
 
40
- private
31
+ Glossarist::GlossaryDefinition::GRAMMAR_INFO_BOOLEAN_ATTRIBUTES.each do |bool_attr|
32
+ define_method(:"part_of_speech_#{bool_attr}_from_yaml") do |model, value|
33
+ model.public_send("#{bool_attr}=", value)
34
+ end
41
35
 
42
- def sanitized_options(options)
43
- hash = symbolize_keys(options)
44
- slice_keys(hash, [
45
- :gender,
46
- :number,
47
- :preposition,
48
- :participle,
49
- :adj,
50
- :verb,
51
- :adverb,
52
- :noun,
53
- :part_of_speech,
54
- ])
36
+ define_method(:"part_of_speech_#{bool_attr}_to_yaml") do |model, doc|
37
+ doc[bool_attr] = model.public_send("#{bool_attr}?")
38
+ end
55
39
  end
56
40
  end
57
41
  end
@@ -1,16 +1,20 @@
1
- # frozen_string_literal: true
1
+ require_relative "symbol"
2
2
 
3
3
  module Glossarist
4
4
  module Designation
5
5
  class GraphicalSymbol < Symbol
6
- attr_accessor :text
7
- attr_accessor :image
6
+ attribute :text, :string
7
+ attribute :image, :string
8
8
 
9
- def to_h
10
- super.merge(
11
- "text" => text,
12
- "image" => image,
13
- )
9
+ yaml do
10
+ map :text, to: :text
11
+ map :image, to: :image
12
+ end
13
+
14
+ def self.of_yaml(hash, options = {})
15
+ hash["type"] = "graphical_symbol"
16
+
17
+ super
14
18
  end
15
19
  end
16
20
  end
@@ -1,18 +1,20 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Glossarist
4
2
  module Designation
5
3
  class LetterSymbol < Symbol
6
- attr_accessor :text
7
- attr_accessor :language
8
- attr_accessor :script
4
+ attribute :text, :string
5
+ attribute :language, :string
6
+ attribute :script, :string
7
+
8
+ yaml do
9
+ map :text, to: :text
10
+ map :language, to: :language
11
+ map :script, to: :script
12
+ end
13
+
14
+ def self.of_yaml(hash, options = {})
15
+ hash["type"] = "letter_symbol"
9
16
 
10
- def to_h
11
- super.merge(
12
- "text" => text,
13
- "language" => language,
14
- "script" => script,
15
- )
17
+ super
16
18
  end
17
19
  end
18
20
  end
@@ -1,20 +1,18 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "base"
4
-
5
1
  module Glossarist
6
2
  module Designation
7
3
  class Symbol < Base
8
- attr_accessor :international
4
+ attribute :international, :boolean
5
+ attribute :type, :string
6
+
7
+ yaml do
8
+ map :international, to: :international
9
+ map :type, to: :type, render_default: true
10
+ end
11
+
12
+ def self.of_yaml(hash, options = {})
13
+ hash["type"] = "symbol" unless hash["type"]
9
14
 
10
- def to_h
11
- {
12
- "type" => Glossarist::Designation::SERIALIZED_TYPES[self.class],
13
- "normative_status" => normative_status,
14
- "geographical_area" => geographical_area,
15
- "designation" => designation,
16
- "international" => international,
17
- }.compact
15
+ super
18
16
  end
19
17
  end
20
18
  end