lib/isodoc/iso/metadata.rb in metanorma-iso-2.1.1 vs lib/isodoc/iso/metadata.rb in metanorma-iso-2.1.2
- old
+ new
@@ -3,15 +3,12 @@
module IsoDoc
module Iso
class Metadata < IsoDoc::Metadata
def initialize(lang, script, i18n)
super
- set(:tc, "XXXX")
- set(:sc, "XXXX")
- set(:wg, "XXXX")
+ DATETYPES.each { |w| @metadata["#{w.gsub(/-/, '_')}date".to_sym] = nil }
set(:editorialgroup, [])
- set(:secretariat, "XXX")
set(:obsoletes, nil)
set(:obsoletes_part, nil)
end
def status_abbrev(stage, _substage, iter, draft, doctype)
@@ -35,17 +32,18 @@
end
def docstatus1(isoxml, docstatus)
set(:stage, docstatus.text)
set(:stage_int, docstatus.text.to_i)
+ set(:substage_int, isoxml.at(ns("//bibdata/status/substage"))&.text)
set(:unpublished, unpublished(docstatus.text))
set(:statusabbr,
status_abbrev(docstatus["abbreviation"] || "??",
- isoxml&.at(ns("//bibdata/status/substage"))&.text,
- isoxml&.at(ns("//bibdata/status/iteration"))&.text,
- isoxml&.at(ns("//bibdata/version/draft"))&.text,
- isoxml&.at(ns("//bibdata/ext/doctype"))&.text))
+ isoxml.at(ns("//bibdata/status/substage"))&.text,
+ isoxml.at(ns("//bibdata/status/iteration"))&.text,
+ isoxml.at(ns("//bibdata/version/draft"))&.text,
+ isoxml.at(ns("//bibdata/ext/doctype"))&.text))
unpublished(docstatus.text) and
set(:stageabbr, docstatus["abbreviation"])
end
def unpublished(status)
@@ -63,58 +61,41 @@
end
end
# we don't leave this to i18n.rb, because we have both English and
# French titles in the same document
- def part_label(lang)
- case lang
- when "en" then "Part"
- when "fr" then "Partie"
- when "ru" then "Часть"
- end
- end
+ PART_LABEL = { en: "Part", fr: "Partie", ru: "Часть" }.freeze
+ AMD_LABEL = { en: "AMENDMENT", fr: "AMENDMENT", ru: "ПОПРАВКА" }.freeze
+ CORR_LABEL = { en: "TECHNICAL CORRIGENDUM",
+ fr: "RECTIFICATIF TECHNIQUE",
+ ru: "ТЕХНИЧЕСКОЕ ИСПРАВЛЕНИЕ" }.freeze
- def amd_label(lang)
- case lang
- when "en", "fr" then "AMENDMENT"
- when "ru" then "ПОПРАВКА"
- end
- end
-
- def corr_label(lang)
- case lang
- when "en" then "TECHNICAL CORRIGENDUM"
- when "fr" then "RECTIFICATIF TECHNIQUE"
- when "ru" then "ТЕХНИЧЕСКОЕ ИСПРАВЛЕНИЕ"
- end
- end
-
def part_title(part, titlenums, lang)
return "" unless part
suffix = @c.encode(part.text, :hexadecimal)
p = titlenums[:part]
titlenums[:part] && titlenums[:subpart] and
p = "#{titlenums[:part]}–#{titlenums[:subpart]}"
titlenums[:part] and
- suffix = "#{part_label(lang)} #{p}: " + suffix
+ suffix = "#{PART_LABEL[lang.to_sym]} #{p}: " + suffix
suffix
end
def part_prefix(titlenums, lang)
p = titlenums[:part]
titlenums[:part] && titlenums[:subpart] and
p = "#{titlenums[:part]}–#{titlenums[:subpart]}"
- "#{part_label(lang)} #{p}"
+ "#{PART_LABEL[lang.to_sym]} #{p}"
end
def amd_prefix(titlenums, lang)
- "#{amd_label(lang)} #{titlenums[:amd]}"
+ "#{AMD_LABEL[lang.to_sym]} #{titlenums[:amd]}"
end
def corr_prefix(titlenums, lang)
- "#{corr_label(lang)} #{titlenums[:corr]}"
+ "#{CORR_LABEL[lang.to_sym]} #{titlenums[:corr]}"
end
def compose_title(tparts, tnums, lang)
main = ""
tparts[:main].nil? or
@@ -128,24 +109,25 @@
end
main
end
def title_nums(isoxml)
- { part: isoxml.at(ns("//bibdata//project-number/@part")),
- subpart: isoxml.at(ns("//bibdata//project-number/@subpart")),
- amd: isoxml.at(ns("//bibdata//project-number/@amendment")),
- corr: isoxml.at(ns("//bibdata//project-number/@corrigendum")) }
+ prefix = "//bibdata/ext/structuredidentifier/project-number"
+ { part: isoxml.at(ns("#{prefix}/@part")),
+ subpart: isoxml.at(ns("#{prefix}/@subpart")),
+ amd: isoxml.at(ns("#{prefix}/@amendment")),
+ corr: isoxml.at(ns("#{prefix}/@corrigendum")) }
end
def title_parts(isoxml, lang)
- { intro: isoxml.at(ns("//bibdata//title[@type='title-intro' and "\
+ { intro: isoxml.at(ns("//bibdata/title[@type='title-intro' and "\
"@language='#{lang}']")),
- main: isoxml.at(ns("//bibdata//title[@type='title-main' and "\
+ main: isoxml.at(ns("//bibdata/title[@type='title-main' and "\
"@language='#{lang}']")),
- part: isoxml.at(ns("//bibdata//title[@type='title-part' and "\
+ part: isoxml.at(ns("//bibdata/title[@type='title-part' and "\
"@language='#{lang}']")),
- amd: isoxml.at(ns("//bibdata//title[@type='title-amd' and "\
+ amd: isoxml.at(ns("//bibdata/title[@type='title-amd' and "\
"@language='#{lang}']")) }
end
def title(isoxml, _out)
lang = case @lang
@@ -195,43 +177,61 @@
def author(xml, _out)
super
tc(xml)
sc(xml)
wg(xml)
+ approvalgroup(xml)
secretariat(xml)
end
def tc(xml)
- tc_type = xml.at(ns("//bibdata/ext/editorialgroup/technical-committee/"\
+ tcid = tc_base(xml, "editorialgroup") or return
+ set(:tc, tcid)
+ set(:editorialgroup, get[:editorialgroup] << tcid)
+ end
+
+ def tc_base(xml, grouptype)
+ tc_num = xml.at(ns("//bibdata/ext/#{grouptype}/"\
+ "technical-committee/@number")) or return nil
+ tc_type = xml.at(ns("//bibdata/ext/#{grouptype}/technical-committee/"\
"@type"))&.text || "TC"
- if tc_num = xml.at(ns("//bibdata/ext/editorialgroup/"\
- "technical-committee/@number"))
- tcid = "#{tc_type} #{tc_num.text}"
- set(:tc, tcid)
- set(:editorialgroup, get[:editorialgroup] << tcid)
- end
+ "#{tc_type} #{tc_num.text}"
end
def sc(xml)
- sc_num = xml.at(ns("//bibdata/ext/editorialgroup/subcommittee/@number"))
- sc_type = xml.at(ns("//bibdata/ext/editorialgroup/subcommittee/"\
+ scid = sc_base(xml, "editorialgroup") or return
+ set(:sc, scid)
+ set(:editorialgroup, get[:editorialgroup] << scid)
+ end
+
+ def sc_base(xml, grouptype)
+ sc_num = xml.at(ns("//bibdata/ext/#{grouptype}/subcommittee/"\
+ "@number")) or return nil
+ sc_type = xml.at(ns("//bibdata/ext/#{grouptype}/subcommittee/"\
"@type"))&.text || "SC"
- if sc_num
- scid = "#{sc_type} #{sc_num.text}"
- set(:sc, scid)
- set(:editorialgroup, get[:editorialgroup] << scid)
- end
+ "#{sc_type} #{sc_num.text}"
end
def wg(xml)
- wg_num = xml.at(ns("//bibdata/ext/editorialgroup/workgroup/@number"))
- wg_type = xml.at(ns("//bibdata/ext/editorialgroup/workgroup/"\
+ wgid = wg_base(xml, "editorialgroup") or return
+ set(:wg, wgid)
+ set(:editorialgroup, get[:editorialgroup] << wgid)
+ end
+
+ def wg_base(xml, grouptype)
+ wg_num = xml.at(ns("//bibdata/ext/#{grouptype}/workgroup/"\
+ "@number")) or return
+ wg_type = xml.at(ns("//bibdata/ext/#{grouptype}/workgroup/"\
"@type"))&.text || "WG"
- if wg_num
- wgid = "#{wg_type} #{wg_num.text}"
- set(:wg, wgid)
- set(:editorialgroup, get[:editorialgroup] << wgid)
- end
+ "#{wg_type} #{wg_num.text}"
+ end
+
+ def approvalgroup(xml)
+ ag = tc_base(xml, "approvalgroup") or return
+ ret = [ag]
+ ret << sc_base(xml, "approvalgroup")
+ ret << wg_base(xml, "approvalgroup")
+ set(:approvalgroup, ret)
end
def secretariat(xml)
sec = xml.at(ns("//bibdata/ext/editorialgroup/secretariat"))
set(:secretariat, sec.text) if sec