Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing (E) from sources #34

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/tc211/termbase/term.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions spec/tc211/termbase/term_spec.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions spec/tc211/termbase_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@
"status" => "identical",
},
],
"authoritativeSource" => [
{ "link" => "https://www.iso.org/standard/20057.html" },
],
ronaldtse marked this conversation as resolved.
Show resolved Hide resolved
"terms" => [
{
"type" => "expression",
Expand Down
Loading