glossarist-new 1.0.0
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.
- checksums.yaml +7 -0
- data/.editorconfig +15 -0
- data/.github/workflows/test.yml +34 -0
- data/.gitignore +18 -0
- data/.hound.yml +3 -0
- data/.rspec +3 -0
- data/.rubocop.yml +35 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +23 -0
- data/README.adoc +11 -0
- data/Rakefile +8 -0
- data/config.yml +83 -0
- data/glossarist.gemspec +36 -0
- data/lib/glossarist/citation.rb +85 -0
- data/lib/glossarist/collection.rb +86 -0
- data/lib/glossarist/concept.rb +143 -0
- data/lib/glossarist/concept_date.rb +20 -0
- data/lib/glossarist/concept_manager.rb +44 -0
- data/lib/glossarist/concept_source.rb +62 -0
- data/lib/glossarist/designation/abbreviation.rb +23 -0
- data/lib/glossarist/designation/base.rb +37 -0
- data/lib/glossarist/designation/expression.rb +50 -0
- data/lib/glossarist/designation/grammar_info.rb +58 -0
- data/lib/glossarist/designation/graphical_symbol.rb +17 -0
- data/lib/glossarist/designation/letter_symbol.rb +19 -0
- data/lib/glossarist/designation/symbol.rb +21 -0
- data/lib/glossarist/designation.rb +27 -0
- data/lib/glossarist/detailed_definition.rb +31 -0
- data/lib/glossarist/glossary_definition.rb +29 -0
- data/lib/glossarist/localized_concept.rb +61 -0
- data/lib/glossarist/managed_concept.rb +107 -0
- data/lib/glossarist/managed_concept_collection.rb +79 -0
- data/lib/glossarist/model.rb +29 -0
- data/lib/glossarist/non_verb_rep.rb +18 -0
- data/lib/glossarist/related_concept.rb +31 -0
- data/lib/glossarist/utilities/boolean_attributes.rb +35 -0
- data/lib/glossarist/utilities/common_functions.rb +29 -0
- data/lib/glossarist/utilities/enum/class_methods.rb +99 -0
- data/lib/glossarist/utilities/enum/enum_collection.rb +45 -0
- data/lib/glossarist/utilities/enum/instance_methods.rb +55 -0
- data/lib/glossarist/utilities/enum.rb +21 -0
- data/lib/glossarist/utilities.rb +5 -0
- data/lib/glossarist/version.rb +8 -0
- data/lib/glossarist.rb +31 -0
- metadata +131 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Glossarist
|
4
|
+
class RelatedConcept < Model
|
5
|
+
include Glossarist::Utilities::Enum
|
6
|
+
|
7
|
+
register_enum :type, Glossarist::GlossaryDefinition::RELATED_CONCEPT_TYPES
|
8
|
+
|
9
|
+
# @return [String]
|
10
|
+
attr_accessor :content
|
11
|
+
|
12
|
+
# Reference to the related concept.
|
13
|
+
# @return [Citation]
|
14
|
+
attr_reader :ref
|
15
|
+
|
16
|
+
def ref=(ref)
|
17
|
+
@ref = Citation.new(ref)
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_h
|
21
|
+
reference = ref&.to_h
|
22
|
+
reference&.merge!(reference&.delete("ref"))
|
23
|
+
|
24
|
+
{
|
25
|
+
"type" => type.to_s,
|
26
|
+
"content" => content,
|
27
|
+
"ref" => reference,
|
28
|
+
}.compact
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Glossarist
|
4
|
+
module Utilities
|
5
|
+
module CommonFunctions
|
6
|
+
# Hash#transform_keys is not available in Ruby 2.4
|
7
|
+
# so we have to do this ourselves :(
|
8
|
+
# symbolize hash keys
|
9
|
+
def symbolize_keys(hash)
|
10
|
+
result = {}
|
11
|
+
hash.each_pair do |key, value|
|
12
|
+
result[key.to_sym] = value
|
13
|
+
end
|
14
|
+
result
|
15
|
+
end
|
16
|
+
|
17
|
+
# Hash#slice is not available in Ruby 2.4
|
18
|
+
# so we have to do this ourselves :(
|
19
|
+
# slice hash keys
|
20
|
+
def slice_keys(hash, keys)
|
21
|
+
result = {}
|
22
|
+
keys.each do |key|
|
23
|
+
result[key] = hash[key] if hash.key?(key)
|
24
|
+
end
|
25
|
+
result
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,99 @@
|
|
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
|
@@ -0,0 +1,45 @@
|
|
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
|
@@ -0,0 +1,55 @@
|
|
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
|
@@ -0,0 +1,21 @@
|
|
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
|
data/lib/glossarist.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# (c) Copyright 2021 Ribose Inc.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "psych"
|
7
|
+
|
8
|
+
require_relative "glossarist/utilities"
|
9
|
+
require_relative "glossarist/version"
|
10
|
+
require_relative "glossarist/glossary_definition"
|
11
|
+
|
12
|
+
require_relative "glossarist/model"
|
13
|
+
require_relative "glossarist/concept_date"
|
14
|
+
require_relative "glossarist/detailed_definition"
|
15
|
+
require_relative "glossarist/related_concept"
|
16
|
+
require_relative "glossarist/citation"
|
17
|
+
require_relative "glossarist/concept_source"
|
18
|
+
require_relative "glossarist/collection"
|
19
|
+
require_relative "glossarist/designation"
|
20
|
+
require_relative "glossarist/concept"
|
21
|
+
require_relative "glossarist/localized_concept"
|
22
|
+
require_relative "glossarist/managed_concept_collection"
|
23
|
+
require_relative "glossarist/concept_manager"
|
24
|
+
require_relative "glossarist/managed_concept"
|
25
|
+
require_relative "glossarist/non_verb_rep"
|
26
|
+
|
27
|
+
module Glossarist
|
28
|
+
class Error < StandardError; end
|
29
|
+
class InvalidTypeError < StandardError; end
|
30
|
+
# Your code goes here...
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: glossarist-new
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ribose
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-05-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.14.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.14.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.10'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- open.source@ribose.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".editorconfig"
|
63
|
+
- ".github/workflows/test.yml"
|
64
|
+
- ".gitignore"
|
65
|
+
- ".hound.yml"
|
66
|
+
- ".rspec"
|
67
|
+
- ".rubocop.yml"
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.adoc
|
71
|
+
- Rakefile
|
72
|
+
- config.yml
|
73
|
+
- glossarist.gemspec
|
74
|
+
- lib/glossarist.rb
|
75
|
+
- lib/glossarist/citation.rb
|
76
|
+
- lib/glossarist/collection.rb
|
77
|
+
- lib/glossarist/concept.rb
|
78
|
+
- lib/glossarist/concept_date.rb
|
79
|
+
- lib/glossarist/concept_manager.rb
|
80
|
+
- lib/glossarist/concept_source.rb
|
81
|
+
- lib/glossarist/designation.rb
|
82
|
+
- lib/glossarist/designation/abbreviation.rb
|
83
|
+
- lib/glossarist/designation/base.rb
|
84
|
+
- lib/glossarist/designation/expression.rb
|
85
|
+
- lib/glossarist/designation/grammar_info.rb
|
86
|
+
- lib/glossarist/designation/graphical_symbol.rb
|
87
|
+
- lib/glossarist/designation/letter_symbol.rb
|
88
|
+
- lib/glossarist/designation/symbol.rb
|
89
|
+
- lib/glossarist/detailed_definition.rb
|
90
|
+
- lib/glossarist/glossary_definition.rb
|
91
|
+
- lib/glossarist/localized_concept.rb
|
92
|
+
- lib/glossarist/managed_concept.rb
|
93
|
+
- lib/glossarist/managed_concept_collection.rb
|
94
|
+
- lib/glossarist/model.rb
|
95
|
+
- lib/glossarist/non_verb_rep.rb
|
96
|
+
- lib/glossarist/related_concept.rb
|
97
|
+
- lib/glossarist/utilities.rb
|
98
|
+
- lib/glossarist/utilities/boolean_attributes.rb
|
99
|
+
- lib/glossarist/utilities/common_functions.rb
|
100
|
+
- lib/glossarist/utilities/enum.rb
|
101
|
+
- lib/glossarist/utilities/enum/class_methods.rb
|
102
|
+
- lib/glossarist/utilities/enum/enum_collection.rb
|
103
|
+
- lib/glossarist/utilities/enum/instance_methods.rb
|
104
|
+
- lib/glossarist/version.rb
|
105
|
+
homepage: https://github.com/glossarist/glossarist-ruby
|
106
|
+
licenses:
|
107
|
+
- BSD-2-Clause
|
108
|
+
metadata:
|
109
|
+
homepage_uri: https://github.com/glossarist/glossarist-ruby
|
110
|
+
source_code_uri: https://github.com/glossarist/glossarist-ruby
|
111
|
+
bug_tracker_uri: https://github.com/glossarist/glossarist-ruby/issues
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 2.4.0
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubygems_version: 3.1.2
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Concept models for terminology glossaries conforming ISO 10241-1.
|
131
|
+
test_files: []
|