diff --git a/lib/tc211/termbase/term.rb b/lib/tc211/termbase/term.rb index 2e21fb4..75c8fd0 100644 --- a/lib/tc211/termbase/term.rb +++ b/lib/tc211/termbase/term.rb @@ -213,6 +213,11 @@ def review_indicator=(value) @review_indicator = value end + def authoritative_source=(source) + clean_source!(source) + @authoritative_source = source + end + # authoritative-source-similarity # Must be one of the following codes: # identical = 1 @@ -228,6 +233,11 @@ def authoritative_source_similarity=(value) @authoritative_source_similarity = value end + def lineage_source=(source) + clean_source!(source) + @lineage_source = source + end + # lineage-source-similarity # Must be one of the following codes: # identical = 1 @@ -243,6 +253,15 @@ def lineage_source_similarity=(value) @lineage_source_similarity = value end + def clean_source!(source) + if source.is_a?(Hash) + source["ref"]&.gsub!(/\(E\),?\s*/, "") + source["clause"]&.gsub!(/\(E\),?\s*/, "") + else + source.gsub!(/\(E\),?\s*/, "") + end + end + ## value Must be one of pending tentative final def review_status=(value) unless ["", "pending", "tentative", "final"].include?(value) diff --git a/spec/tc211/termbase/term_spec.rb b/spec/tc211/termbase/term_spec.rb new file mode 100644 index 0000000..5723ce0 --- /dev/null +++ b/spec/tc211/termbase/term_spec.rb @@ -0,0 +1,28 @@ +RSpec.describe Tc211::Termbase::Term do + describe ".authoritative_source=" do + context "when contains '(E)'" do + let(:authoritative_source) do + { + "ref" => "ISO/TS 19159-4:2022", + "clause" => "(E), 3.22", + "link" => "http://foobar.com", + } + end + + let(:expected_authoritative_source) do + { + "ref" => "ISO/TS 19159-4:2022", + "clause" => "3.22", + "link" => "http://foobar.com", + } + end + + it "expect to remove '(E)' from source" do + expect { subject.authoritative_source = authoritative_source } + .to change { subject.authoritative_source } + .from(nil) + .to(expected_authoritative_source) + end + end + end +end diff --git a/spec/tc211/termbase_spec.rb b/spec/tc211/termbase_spec.rb index e2a7bdf..0cc2814 100644 --- a/spec/tc211/termbase_spec.rb +++ b/spec/tc211/termbase_spec.rb @@ -116,9 +116,6 @@ "status" => "identical", }, ], - "authoritativeSource" => [ - { "link" => "https://www.iso.org/standard/20057.html" }, - ], "terms" => [ { "type" => "expression",