From ee7140c925d4c1a87ecaeea371991241821dd74b Mon Sep 17 00:00:00 2001 From: HassanAkbar Date: Wed, 23 Aug 2023 14:30:43 +0500 Subject: [PATCH] feat: add sources at concept level --- lib/glossarist/managed_concept.rb | 12 ++++++++++++ .../003a8c14-f962-5688-aefe-38c736bebfb2.yaml | 7 +++++++ spec/unit/managed_concept_spec.rb | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/lib/glossarist/managed_concept.rb b/lib/glossarist/managed_concept.rb index d044284..117bda7 100644 --- a/lib/glossarist/managed_concept.rb +++ b/lib/glossarist/managed_concept.rb @@ -26,6 +26,10 @@ class ManagedConcept < Model # @return [Array] attr_reader :groups + # List of authorative sources. + # @return [Array] + attr_reader :sources + # All localizations for this concept. # # Keys are language codes and values are instances of {LocalizedConcept}. @@ -78,6 +82,12 @@ def localized_concepts=(localized_concepts) end end + def sources=(sources) + @sources = sources&.map do |source| + ConceptSource.new(source) + end || [] + end + def localizations=(localizations) return unless localizations @@ -124,6 +134,7 @@ def to_h "identifier" => id, "localized_concepts" => localized_concepts, "groups" => groups, + "sources" => sources&.map(&:to_h), }.compact, }.compact end @@ -172,6 +183,7 @@ def managed_concept_attributes localizedConcepts localizations groups + sources ].compact end diff --git a/spec/fixtures/concept_collection_v2/concept/003a8c14-f962-5688-aefe-38c736bebfb2.yaml b/spec/fixtures/concept_collection_v2/concept/003a8c14-f962-5688-aefe-38c736bebfb2.yaml index 0631599..1d474e0 100644 --- a/spec/fixtures/concept_collection_v2/concept/003a8c14-f962-5688-aefe-38c736bebfb2.yaml +++ b/spec/fixtures/concept_collection_v2/concept/003a8c14-f962-5688-aefe-38c736bebfb2.yaml @@ -3,6 +3,13 @@ data: identifier: '2119' localized_concepts: eng: da24b782-1551-5128-a043-ba6135a25acf + groups: + - chess-piece + - king + sources: + - type: authoritative + origin: + ref: Concept level source dateAccepted: 2023-04-17 id: 003a8c14-f962-5688-aefe-38c736bebfb2 related: [] diff --git a/spec/unit/managed_concept_spec.rb b/spec/unit/managed_concept_spec.rb index 9cbd147..7e79ee5 100644 --- a/spec/unit/managed_concept_spec.rb +++ b/spec/unit/managed_concept_spec.rb @@ -80,6 +80,24 @@ end end + describe "#sources" do + let(:source) do + { + "status" => "identical", + "origin" => { "text" => "Concept level source" }, + } + end + + it "sets the sources list at the concept level" do + expect(subject.sources).to be_nil + + subject.sources = [source] + + expect(subject.sources.first.status).to eq(source["status"]) + expect(subject.sources.first.origin.text).to eq(source["origin"]["text"]) + end + end + describe "#to_h" do let(:expected_concept_hash) do {