Skip to content

Commit

Permalink
feat: add sources at concept level
Browse files Browse the repository at this point in the history
  • Loading branch information
HassanAkbar committed Nov 14, 2023
1 parent 72082e7 commit ee7140c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/glossarist/managed_concept.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class ManagedConcept < Model
# @return [Array<String>]
attr_reader :groups

# List of authorative sources.
# @return [Array<ConceptSource>]
attr_reader :sources

# All localizations for this concept.
#
# Keys are language codes and values are instances of {LocalizedConcept}.
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -124,6 +134,7 @@ def to_h
"identifier" => id,
"localized_concepts" => localized_concepts,
"groups" => groups,
"sources" => sources&.map(&:to_h),
}.compact,
}.compact
end
Expand Down Expand Up @@ -172,6 +183,7 @@ def managed_concept_attributes
localizedConcepts
localizations
groups
sources
].compact
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
Expand Down
18 changes: 18 additions & 0 deletions spec/unit/managed_concept_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit ee7140c

Please sign in to comment.