From a9d0ee0e470685db05f47a4df753995dd793fd2d Mon Sep 17 00:00:00 2001 From: HassanAkbar Date: Wed, 27 Dec 2023 13:17:29 +0500 Subject: [PATCH] feat: add sources at concept level (#78) * feat: add sources at concept level * updated fixtures to include concept level source --- lib/glossarist/managed_concept.rb | 12 ++++++++++++ .../003a8c14-f962-5688-aefe-38c736bebfb2.yaml | 6 ++++++ spec/unit/managed_concept_spec.rb | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/lib/glossarist/managed_concept.rb b/lib/glossarist/managed_concept.rb index 77d9fa1..0cc8951 100644 --- a/lib/glossarist/managed_concept.rb +++ b/lib/glossarist/managed_concept.rb @@ -28,6 +28,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}. @@ -87,6 +91,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 @@ -134,6 +144,7 @@ def to_h "identifier" => id, "localized_concepts" => localized_concepts.empty? ? nil : localized_concepts, "groups" => groups, + "sources" => sources&.map(&:to_h), }.compact, }.compact end @@ -182,6 +193,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 483f456..adb2ee0 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,3 +3,9 @@ data: identifier: '2119' localized_concepts: eng: da24b782-1551-5128-a043-ba6135a25acf + sources: + - origin: + ref: ISO 1087-1:2000 + clause: 3.2.9 + link: https://www.iso.org/standard/20057.html + type: authoritative 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 {