Skip to content

Commit

Permalink
feat: add sources at concept level (#78)
Browse files Browse the repository at this point in the history
* feat: add sources at concept level

* updated fixtures to include concept level source
  • Loading branch information
HassanAkbar authored Dec 27, 2023
1 parent e0d857d commit a9d0ee0
Show file tree
Hide file tree
Showing 3 changed files with 36 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 @@ -28,6 +28,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 @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -182,6 +193,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,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
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 a9d0ee0

Please sign in to comment.