Skip to content

Commit

Permalink
feat: extract domain from term
Browse files Browse the repository at this point in the history
  • Loading branch information
HassanAkbar authored and ronaldtse committed May 16, 2024
1 parent 0ff36bd commit 3557d67
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/tc211/termbase/term.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Term
language_code
notes
examples
domain
entry_status
classification
review_indicator
Expand Down Expand Up @@ -120,6 +121,8 @@ def initialize(options = {})
6 => "unspecified",
}.freeze

DOMAIN_REGEX = /^(.*?)<([^>]*?)>$/.freeze

def add_example(example)
c = clean_prefixed_string(example, EXAMPLE_PREFIXES)
@examples << c unless c.empty?
Expand Down Expand Up @@ -288,6 +291,31 @@ def retired?
release >= 0
end

def term=(value)
extract_domain_and_set_var(:term, value)
end

def alt=(value)
extract_domain_and_set_var(:alt, value)
end

def abbrev=(value)
extract_domain_and_set_var(:abbrev, value)
end

def synonyms=(value)
extract_domain_and_set_var(:synonyms, value)
end

def extract_domain_and_set_var(var_name, value)
if match_data = value.strip.match(DOMAIN_REGEX)
instance_variable_set("@#{var_name}", match_data[1].strip)
@domain ||= match_data[2].strip
else
instance_variable_set("@#{var_name}", value)
end
end

def terms
[
primary_term_hash,
Expand Down
16 changes: 16 additions & 0 deletions spec/tc211/termbase_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,22 @@
end
end

context "concept 11" do
let(:concept) { collection.fetch("11") }

it "should have 11 localized concepts" do
expect(concept.localized_concepts.count).to be(11)
end

context "eng localization" do
let(:localized_concept) { concept.localization("eng") }

it "should have UML as domain" do
expect(localized_concept.domain).to eq("UML")
end
end
end

context "concept 18" do
let(:concept) { collection.fetch("18") }

Expand Down

0 comments on commit 3557d67

Please sign in to comment.