Skip to content

Commit

Permalink
updated to use glossarist models for concept and managed_concept
Browse files Browse the repository at this point in the history
  • Loading branch information
HassanAkbar committed Mar 1, 2024
1 parent 25dc7fe commit c71a3be
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 4 deletions.
10 changes: 10 additions & 0 deletions lib/tc211/termbase.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
require "glossarist"
require "tc211/termbase/version"

require_relative "termbase/glossarist/concept"
require_relative "termbase/glossarist/managed_concept"

module Tc211
module Termbase
class Error < StandardError; end

# Your code goes here...
::Glossarist.configure do |config|
config.register_extension_attributes(["authoritativeSource"])

config.register_class(:localized_concept, Tc211::Termbase::Glossarist::Concept)
config.register_class(:managed_concept, Tc211::Termbase::Glossarist::ManagedConcept)
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tc211/termbase/concept.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def to_file(filename)
end

def to_glossarist_concept
concept = Glossarist::ManagedConcept.new(data: { id: id.to_s })
concept = Tc211::Termbase::Glossarist::ManagedConcept.new(data: { id: id.to_s })

localized_concepts = []

Expand Down
2 changes: 1 addition & 1 deletion lib/tc211/termbase/concept_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def to_file(filename)
end

def to_concept_collection
collection = Glossarist::ManagedConceptCollection.new
collection = ::Glossarist::ManagedConceptCollection.new

values.each do |term_concept|
next if term_concept.nil?
Expand Down
27 changes: 27 additions & 0 deletions lib/tc211/termbase/glossarist/concept.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Tc211::Termbase
module Glossarist
class Concept < ::Glossarist::LocalizedConcept
attr_accessor :status, :dateAccepted

def uuid
@uuid ||= ::Glossarist::Utilities::UUID.uuid_v5(
::Glossarist::Utilities::UUID::OID_NAMESPACE,
to_h(only_data: true).to_yaml,
)
end

def to_h(only_data: false)
date_accepted = dates.find(&:accepted?)

data_hash = super()
return data_hash if only_data

data_hash.merge({
"dateAccepted" => date_accepted&.date&.dup,
"id" => uuid,
"status" => entry_status,
}.compact)
end
end
end
end
27 changes: 27 additions & 0 deletions lib/tc211/termbase/glossarist/managed_concept.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Tc211::Termbase
module Glossarist
class ManagedConcept < ::Glossarist::ManagedConcept
attr_accessor :status

def uuid
@uuid ||= ::Glossarist::Utilities::UUID.uuid_v5(
::Glossarist::Utilities::UUID::OID_NAMESPACE,
to_h(only_data: true).to_yaml,
)
end

def to_h(only_data: false)
data_hash = super()
return data_hash if only_data

date_accepted = default_lang.dates.find(&:accepted?)
data_hash.merge({
"dateAccepted" => date_accepted&.date&.dup,
"id" => uuid,
"related" => related&.map(&:to_h) || [],
"status" => default_lang.entry_status,
}.compact)
end
end
end
end
8 changes: 8 additions & 0 deletions lib/tc211/termbase/term.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,12 @@ def authoritative_source_hash
}
end

def authoritative_source_array
return unless authoritative_source

[ "link" => authoritative_source["link"] ]
end

def lineage_source_hash
return unless lineage_source

Expand Down Expand Up @@ -371,6 +377,8 @@ def to_localized_concept_hash
localized_concept_hash["id"] = localized_concept_hash["id"].to_s
localized_concept_hash["sources"] = sources_hash

localized_concept_hash["authoritativeSource"] = authoritative_source_array if authoritative_source_array

localized_concept_hash
end
end
Expand Down
12 changes: 10 additions & 2 deletions spec/tc211/termbase_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "pry"

RSpec.describe Tc211::Termbase do
it "has a version number" do
expect(Tc211::Termbase::VERSION).not_to be nil
Expand Down Expand Up @@ -116,6 +118,9 @@
"status" => "identical",
},
],
"authoritativeSource" => [
{ "link"=>"https://www.iso.org/standard/20057.html" }
],
"terms" => [
{
"type" => "expression",
Expand All @@ -127,8 +132,11 @@
"entry_status" => "valid",
"review_date" => Time.parse("2013-01-29 00:00:00"),
"review_decision_date" => Time.parse("2016-10-01 00:00:00"),
"review_decision_event" => "Publication of ISO 19104:2016"
}
"review_decision_event" => "Publication of ISO 19104:2016",
},
"dateAccepted" => Time.parse("2008-11-15"),
"id" => "e59bc5ef-54aa-5d99-bf52-de87ea129979",
"status" => "valid"
}
end

Expand Down

0 comments on commit c71a3be

Please sign in to comment.