glossarist 0.1.2 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81224c902256db7a2b325cc0969d35d044c52ee7a30e67c9c5c77c25c661ca45
4
- data.tar.gz: db259d46d23ba8f78bedb40c998cae8ab5e5e46ef5debf3f63360c5ab420dd81
3
+ metadata.gz: 15883cde9ccc6f1d81e6851314ef7cae3835fd679c320b961be4310eea0e3384
4
+ data.tar.gz: b0821aa718dbc0caa858ff5d1ab0723937e4c527d9a98a6a182f4976637d32d0
5
5
  SHA512:
6
- metadata.gz: b141c56e7cce306ebdaca6c67f813de0fbfae1dbc343b576842d5515f54dba7f2a9861aaca60505ccf7ae49b6cc5a53279409dd3892d19b9b4d94a4007438298
7
- data.tar.gz: 16bc4e45b695adbe4ac4a8c6e1a6b6dbd47bf981f70342f29f223c0f8a77a05c7f1bbb0ee2a862398ed80c8599e3ffc1873e37e2b3c6fea5fbcc86a480662434
6
+ metadata.gz: 295691e8f62944ea642ed41861146e0d321ec2c793d519227d1ad1cdde174787d8ad9a219bfbe19a3d4b7eb60395a53c37f6375151cc5a89a707694367614be4
7
+ data.tar.gz: 6a0c63bfd7b33bc7803e0daa685d677dc6bb061e4bf09be415878f10e72c3c836285d36b38da61628438ea7c9afb0d03eed566a1f8a9af5993990ffc6fe819c3
data/lib/glossarist.rb CHANGED
@@ -10,6 +10,7 @@ require_relative "glossarist/version"
10
10
  require_relative "glossarist/model"
11
11
  require_relative "glossarist/concept"
12
12
  require_relative "glossarist/collection"
13
+ require_relative "glossarist/designations"
13
14
  require_relative "glossarist/localized_concept"
14
15
 
15
16
  module Glossarist
@@ -70,7 +70,7 @@ module Glossarist
70
70
 
71
71
  def default_designation
72
72
  localized = localization("eng") || localizations.values.first
73
- localized&.terms&.dig(0, "designation")
73
+ localized&.terms&.first&.designation
74
74
  end
75
75
 
76
76
  def related_concepts
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ # (c) Copyright 2021 Ribose Inc.
4
+ #
5
+
6
+ module Glossarist
7
+ module Designations
8
+ class Base < Model
9
+ # @note This is not entirely aligned with agreed schema and may be
10
+ # changed.
11
+ attr_accessor :designation
12
+
13
+ attr_accessor :normative_status
14
+ attr_accessor :geographical_area
15
+
16
+ def self.from_h(hash)
17
+ type = hash["type"]
18
+
19
+ if type.nil? || /\w/ !~ type
20
+ raise ArgumentError, "designation type is missing"
21
+ end
22
+
23
+ designation_subclass = SERIALIZED_TYPES[type]
24
+
25
+ if self == Base
26
+ # called on Base class, delegate it to proper subclass
27
+ SERIALIZED_TYPES[type].from_h(hash)
28
+ else
29
+ # called on subclass, instantiate object
30
+ unless SERIALIZED_TYPES[self] == type
31
+ raise ArgumentError, "unexpected designation type: #{type}"
32
+ end
33
+ super(hash.reject { |k, _| k == "type" })
34
+ end
35
+ end
36
+ end
37
+
38
+ class Expression < Base
39
+ attr_accessor :gender
40
+ attr_accessor :part_of_speech
41
+ attr_accessor :plurality
42
+ attr_accessor :prefix
43
+ attr_accessor :usage_info
44
+
45
+ def to_h
46
+ {
47
+ "type" => "expression",
48
+ "prefix" => prefix,
49
+ "normative_status" => normative_status,
50
+ "usage_info" => usage_info,
51
+ "designation" => designation,
52
+ "part_of_speech" => part_of_speech,
53
+ "geographical_area" => geographical_area,
54
+ "gender" => gender,
55
+ "plurality" => plurality,
56
+ }.compact
57
+ end
58
+ end
59
+
60
+ class Symbol < Base
61
+ attr_accessor :international
62
+
63
+ def to_h
64
+ {
65
+ "type" => "symbol",
66
+ "normative_status" => normative_status,
67
+ "geographical_area" => geographical_area,
68
+ "designation" => designation,
69
+ "international" => international,
70
+ }.compact
71
+ end
72
+ end
73
+
74
+ # Bi-directional class-to-string mapping for STI-like serialization.
75
+ SERIALIZED_TYPES = {
76
+ Expression => "expression",
77
+ Symbol => "symbol",
78
+ }
79
+ .tap { |h| h.merge!(h.invert) }
80
+ .freeze
81
+ end
82
+ end
@@ -16,9 +16,7 @@ module Glossarist
16
16
 
17
17
  # Concept designations.
18
18
  # @todo Alias +terms+ exists only for legacy reasons and will be removed.
19
- # @todo Right now accepts hashes for legacy reasons, but they will be
20
- # replaced with dedicated classes.
21
- # @return [Array<Hash>]
19
+ # @return [Array<Designations::Base>]
22
20
  attr_accessor :designations
23
21
  alias :terms :designations
24
22
  alias :terms= :designations=
@@ -84,7 +82,7 @@ module Glossarist
84
82
  def to_h # rubocop:disable Metrics/MethodLength
85
83
  {
86
84
  "id" => id,
87
- "terms" => terms,
85
+ "terms" => (terms&.map(&:to_h) || []),
88
86
  "definition" => definition,
89
87
  "language_code" => language_code,
90
88
  "notes" => notes,
@@ -100,6 +98,11 @@ module Glossarist
100
98
  }.compact
101
99
  end
102
100
 
101
+ def self.from_h(hash)
102
+ terms = hash["terms"]&.map { |h| Designations::Base.from_h(h) } || []
103
+ super(hash.merge({"terms" => terms}))
104
+ end
105
+
103
106
  # @deprecated For legacy reasons only.
104
107
  # Implicit conversion (i.e. {#to_hash} alias) will be removed soon.
105
108
  alias :to_hash :to_h
@@ -4,5 +4,5 @@
4
4
  #
5
5
 
6
6
  module Glossarist
7
- VERSION = "0.1.2"
7
+ VERSION = "0.2.0"
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glossarist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose
@@ -73,6 +73,7 @@ files:
73
73
  - lib/glossarist.rb
74
74
  - lib/glossarist/collection.rb
75
75
  - lib/glossarist/concept.rb
76
+ - lib/glossarist/designations.rb
76
77
  - lib/glossarist/localized_concept.rb
77
78
  - lib/glossarist/model.rb
78
79
  - lib/glossarist/version.rb