glossarist 2.3.0 → 2.3.2

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 (48) 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/exe/glossarist +5 -3
  7. data/glossarist.gemspec +1 -0
  8. data/lib/glossarist/asset.rb +4 -9
  9. data/lib/glossarist/citation.rb +73 -41
  10. data/lib/glossarist/collection.rb +2 -11
  11. data/lib/glossarist/collections/asset_collection.rb +0 -3
  12. data/lib/glossarist/collections/bibliography_collection.rb +1 -1
  13. data/lib/glossarist/concept.rb +66 -206
  14. data/lib/glossarist/concept_data.rb +66 -0
  15. data/lib/glossarist/concept_date.rb +7 -11
  16. data/lib/glossarist/concept_manager.rb +19 -29
  17. data/lib/glossarist/concept_set.rb +6 -4
  18. data/lib/glossarist/concept_source.rb +15 -58
  19. data/lib/glossarist/config.rb +4 -4
  20. data/lib/glossarist/designation/abbreviation.rb +15 -16
  21. data/lib/glossarist/designation/base.rb +16 -15
  22. data/lib/glossarist/designation/expression.rb +18 -26
  23. data/lib/glossarist/designation/grammar_info.rb +27 -45
  24. data/lib/glossarist/designation/graphical_symbol.rb +12 -8
  25. data/lib/glossarist/designation/letter_symbol.rb +13 -11
  26. data/lib/glossarist/designation/symbol.rb +11 -13
  27. data/lib/glossarist/designation.rb +3 -3
  28. data/lib/glossarist/detailed_definition.rb +6 -24
  29. data/lib/glossarist/error.rb +4 -4
  30. data/lib/glossarist/glossary_definition.rb +6 -3
  31. data/lib/glossarist/localized_concept.rb +17 -62
  32. data/lib/glossarist/managed_concept.rb +73 -146
  33. data/lib/glossarist/managed_concept_collection.rb +15 -24
  34. data/lib/glossarist/managed_concept_data.rb +47 -0
  35. data/lib/glossarist/non_verb_rep.rb +10 -13
  36. data/lib/glossarist/related_concept.rb +14 -21
  37. data/lib/glossarist/utilities/uuid.rb +10 -5
  38. data/lib/glossarist/utilities.rb +0 -2
  39. data/lib/glossarist/version.rb +1 -1
  40. data/lib/glossarist.rb +10 -9
  41. metadata +23 -13
  42. data/lib/glossarist/model.rb +0 -40
  43. data/lib/glossarist/utilities/boolean_attributes.rb +0 -35
  44. data/lib/glossarist/utilities/enum/class_methods.rb +0 -99
  45. data/lib/glossarist/utilities/enum/enum_collection.rb +0 -45
  46. data/lib/glossarist/utilities/enum/instance_methods.rb +0 -55
  47. data/lib/glossarist/utilities/enum.rb +0 -21
  48. data/lib/glossarist/v1_reader.rb +0 -28
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # (c) Copyright 2021 Ribose Inc.
4
- #
5
-
6
- module Glossarist
7
- class Model
8
- def self.new(params = {})
9
- return params if params.is_a?(self)
10
-
11
- super
12
- end
13
-
14
- def initialize(attributes = {})
15
- attributes.each_pair { |k, v| set_attribute(k, v) }
16
- end
17
-
18
- def set_attribute(name, value)
19
- public_send("#{name}=", value)
20
- rescue NoMethodError
21
- if Config.extension_attributes.include?(name)
22
- extension_attributes[name] = value
23
- elsif name.match?(/[A-Z]/) # adding support for camel case
24
- name = snake_case(name.to_s).to_sym
25
- retry
26
- else
27
- raise ArgumentError, "#{self.class.name} does not have " +
28
- "attribute #{name} defined or the attribute is read only."
29
- end
30
- end
31
-
32
- def self.from_h(hash)
33
- new(hash)
34
- end
35
-
36
- def snake_case(str)
37
- str.gsub(/([A-Z])/) { "_#{$1.downcase}" }
38
- end
39
- end
40
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Glossarist
4
- module Utilities
5
- module BooleanAttributes
6
- def self.included(base)
7
- base.extend(ClassMethods)
8
- end
9
-
10
- def self.extended(base)
11
- base.extend(ClassMethods)
12
- end
13
-
14
- module ClassMethods
15
- def register_boolean_attributes(attributes)
16
- attributes.each do |attribute|
17
- register_boolean_attribute(attribute)
18
- end
19
- end
20
-
21
- def register_boolean_attribute(attribute)
22
- attr_reader attribute
23
-
24
- define_method("#{attribute}=") do |value|
25
- instance_variable_set("@#{attribute}", !!value)
26
- end
27
-
28
- define_method("#{attribute}?") do
29
- !!instance_variable_get("@#{attribute}")
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,99 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "set"
4
-
5
- module Glossarist
6
- module Utilities
7
- module Enum
8
- module ClassMethods
9
- def add_inheritable_attribute(attribute)
10
- @inheritable_attributes ||= Set[:inheritable_attributes]
11
- @inheritable_attributes << attribute
12
- end
13
-
14
- def inherited(subclass)
15
- @inheritable_attributes.each do |inheritable_attribute|
16
- instance_var = "@#{inheritable_attribute}"
17
- subclass.instance_variable_set(instance_var, instance_variable_get(instance_var))
18
- end
19
- end
20
-
21
- def enums
22
- @enums ||= EnumCollection.new
23
- end
24
-
25
- def register_enum(name, values, options = {})
26
- values = standardize_values(values)
27
-
28
- enums.add(name, values, options)
29
-
30
- add_inheritable_attribute(:enums)
31
- register_type_accessor(name)
32
-
33
- values.each do |value|
34
- register_check_method(name, value)
35
- register_set_method(name, value)
36
- end
37
- end
38
-
39
- def registered_enums
40
- enums.registered_enums
41
- end
42
-
43
- def valid_types(name)
44
- enums.valid_types(name)
45
- end
46
-
47
- def type_options(name)
48
- enums.type_options(name)
49
- end
50
-
51
- def register_type_reader(name)
52
- define_method(name) do
53
- if self.class.type_options(name)[:multiple]
54
- selected_type[name].map(&:to_s)
55
- else
56
- selected_type[name].first&.to_s
57
- end
58
- end
59
- end
60
-
61
- def register_type_writer(name)
62
- define_method("#{name}=") do |type|
63
- select_type(name, type)
64
- end
65
- end
66
-
67
- # Adds a reader and writer for the type name given.
68
- def register_type_accessor(name)
69
- register_type_reader(name)
70
- register_type_writer(name)
71
- end
72
-
73
- def register_check_method(name, value)
74
- define_method("#{value}?") do
75
- !!selected_type[name]&.include?(value.to_sym)
76
- end
77
- end
78
-
79
- def register_set_method(name, value)
80
- define_method("#{value}=") do |input|
81
- if input
82
- select_type(name, value)
83
- else
84
- deselect_type(name, value)
85
- end
86
- end
87
- end
88
-
89
- def standardize_values(values)
90
- if values.is_a?(Array)
91
- values.map(&:to_sym)
92
- else
93
- [values.to_sym]
94
- end
95
- end
96
- end
97
- end
98
- end
99
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Glossarist
4
- module Utilities
5
- module Enum
6
- class EnumCollection
7
- include Enumerable
8
-
9
- def initialize
10
- @collection = {}
11
- end
12
-
13
- def add(name, values, options = {})
14
- @collection[name] = { registered_values: values, options: options }
15
- end
16
-
17
- def each(&block)
18
- if block_given?
19
- @collection.each do |object|
20
- block.call(object)
21
- end
22
- else
23
- enum_for(:each)
24
- end
25
- end
26
-
27
- def registered_enums
28
- @collection&.keys || []
29
- end
30
-
31
- def valid_types(name)
32
- @collection[name][:registered_values]
33
- end
34
-
35
- def type_options(name)
36
- @collection[name][:options]
37
- end
38
-
39
- def [](name)
40
- @collection[name]
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Glossarist
4
- module Utilities
5
- module Enum
6
- module InstanceMethods
7
- def selected_type
8
- initialize_selected_type if @selected_type.nil?
9
-
10
- @selected_type
11
- end
12
-
13
- def select_type(type_name, values)
14
- values = if values.is_a?(Array)
15
- values
16
- else
17
- [values]
18
- end
19
-
20
- values.each do |value|
21
- select_type_value(type_name, value)
22
- end
23
- end
24
-
25
- def deselect_type(type_name, value)
26
- selected_type[type_name].delete(value)
27
- end
28
-
29
- private
30
-
31
- def select_type_value(type_name, value)
32
- if !value
33
- selected_type[type_name].clear
34
- elsif self.class.valid_types(type_name).include?(value.to_sym)
35
- selected_type[type_name].clear unless self.class.type_options(type_name)[:multiple]
36
- selected_type[type_name] << value.to_sym
37
- else
38
- raise(
39
- Glossarist::InvalidTypeError,
40
- "`#{value}` is not a valid #{type_name}. Supported #{type_name} are #{self.class.enums[type_name][:registered_values].to_a.join(", ")}"
41
- )
42
- end
43
- end
44
-
45
- def initialize_selected_type
46
- @selected_type = {}
47
-
48
- self.class.registered_enums.each do |type|
49
- @selected_type[type] = []
50
- end
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "enum/enum_collection"
4
- require_relative "enum/class_methods"
5
- require_relative "enum/instance_methods"
6
-
7
- module Glossarist
8
- module Utilities
9
- module Enum
10
- def self.included(base)
11
- base.include(InstanceMethods)
12
- base.extend(ClassMethods)
13
- end
14
-
15
- def self.extended(base)
16
- base.include(InstanceMethods)
17
- base.extend(ClassMethods)
18
- end
19
- end
20
- end
21
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Glossarist
4
- # An adapter to read concepts in V1 format, converts them to v2 format and
5
- # load into glossarist concept model.
6
- class V1Reader
7
- def self.load_concept_from_file(filename)
8
- new.load_concept_from_file(filename)
9
- end
10
-
11
- def load_concept_from_file(filename)
12
- concept_hash = Psych.safe_load(File.read(filename), permitted_classes: [Date, Time])
13
- Config.class_for(:managed_concept).new(generate_v2_concept_hash(concept_hash))
14
- end
15
-
16
- private
17
-
18
- def generate_v2_concept_hash(concept_hash)
19
- v2_concept = { "groups" => concept_hash["groups"] }
20
- v2_concept["data"] = {
21
- "identifier" => concept_hash["termid"],
22
- "localized_concepts" => concept_hash.values.grep(Hash),
23
- }
24
-
25
- v2_concept
26
- end
27
- end
28
- end