From 240a901052e696621bfdb153c62a29db811aec40 Mon Sep 17 00:00:00 2001 From: Ronald Tse Date: Tue, 16 Nov 2021 12:58:53 +0800 Subject: [PATCH] Fix authoritative source references for IEV, fixes #9 --- scripts/split_codes.rb | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/scripts/split_codes.rb b/scripts/split_codes.rb index f390388..275709e 100755 --- a/scripts/split_codes.rb +++ b/scripts/split_codes.rb @@ -31,10 +31,40 @@ def fix_image_paths(string) def fix_github_issues(string) swap_term_refs(fix_image_paths(string)) end + + def get_source_string(termyaml) + return unless termyaml + return unless termyaml.first + source_data = termyaml.first + + source_string = "[.source]\n" + + # TODO: Problem here is that the `ref`s cannot be added to the bibliography + # e.g. in 192-01-17, the source is ISO 9000. + # but we can't add a proper reference here unless we have that in the + # bibliography. + if source_data["ref"].match(/^IEC 60050/) && !source_data["clause"].nil? + source_string += "<>" + else + source_string += source_data["ref"] + if source_data["clause"] + source_string += ", #{source_data["clause"]}" + end + end + + if source_data["relationship"] + if source_data["relationship"]["type"] == "modified" + source_string += ", #{source_data["relationship"]["modification"]}" + end + end + + end + def process_codes(yaml) english = yaml["eng"] definition = fix_github_issues(english["definition"]) + source = get_source_string(english["authoritative_source"]) # puts english.inspect <<~EOF @@ -75,14 +105,7 @@ def process_codes(yaml) end.join("\n") } - #{ - if english["authoritative_source"] - string = "[.source]\n" - string = string + english["authoritative_source"].first["ref"] - string = string + ", " + english["authoritative_source"].first["clause"] if english["authoritative_source"].first["clause"] - string - end - } + #{source} EOF end