Class: IsoDoc::Gb::Metadata

Inherits:
Metadata
  • Object
show all
Defined in:
lib/isodoc/gb/metadata.rb

Overview

A Converter implementation that generates GB output, and a document schema encapsulation of the document for validation

Constant Summary collapse

STAGE_ABBRS =

from ISO

{
  "00": "PWI",
  "10": "NWIP",
  "20": "WD",
  "30": "CD",
  "40": "DIS",
  "50": "FDIS",
  "60": "IS",
  "90": "(Review)",
  "95": "(Withdrawal)",
}.freeze
STAGE_ABBRS_CN =
{
  "00": "新工作项目建议",
  "10": "新工作项目",
  "20": "标准草案工作组讨论稿",
  "30": "标准草案征求意见稿",
  "40": "标准草案送审稿",
  "50": "标准草案报批稿",
  "60": "国家标准",
  "90": "(Review)",
  "95": "(Withdrawal)",
}.freeze
STATUS_CSS =
{
  "00": "working-draft",
  "10": "working-draft",
  "20": "working-draft",
  "30": "committee-draft",
  "40": "draft-standard",
  "50": "draft-standard",
  "60": "standard",
  "90": "standard",
  "95": "obsolete",
}
ISO_STD_XPATH =
"//bibdata/relation[@type = 'equivalent' or "\
"@type = 'identical' or @type = 'nonequivalent']/bibitem".freeze

Instance Method Summary collapse

Constructor Details

#initialize(lang, script, labels) ⇒ Metadata

Returns a new instance of Metadata.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/isodoc/gb/metadata.rb', line 9

def initialize(lang, script, labels)
  super
  set(:docmaintitlezh, "")
  set(:docsubtitlezh, "XXXX")
  set(:docparttitlezh, "")
  set(:docmaintitleen, "")
  set(:docsubtitleen, "XXXX")
  set(:docparttitleen, "")
  set(:gbequivalence, "")
  set(:isostandard, nil)
  set(:isostandardtitle, "")
  set(:doctitle, "XXXX")
  set(:obsoletes, nil)
  set(:obsoletes_part, nil)
end

Instance Method Details

#author(isoxml, _out) ⇒ Object



60
61
62
63
# File 'lib/isodoc/gb/metadata.rb', line 60

def author(isoxml, _out)
  gbcommittee = isoxml.at(ns("//bibdata/gbcommittee"))
  set(:committee, gbcommittee&.text)
end

#bibdate(isoxml, _out) ⇒ Object



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/isodoc/gb/metadata.rb', line 214

def bibdate(isoxml, _out)
  super
  m = get
  if @lang == "zh"
    set(:labelled_publisheddate, m[:publisheddate] + " " +
        @labels["publicationdate_lbl"])
    set(:labelled_implementeddate, m[:implementeddate] + " " +
        @labels["implementationdate_lbl"])
  else
    set(:labelled_publisheddate, @labels["publicationdate_lbl"] +
        ": " + m[:publisheddate])
    set(:labelled_implementeddate,
        @labels["implementationdate_lbl"] + ": " +
        m[:implementeddate])
  end
end

#docid(isoxml, _out) ⇒ Object



139
140
141
142
143
144
# File 'lib/isodoc/gb/metadata.rb', line 139

def docid(isoxml, _out)
  docid1(isoxml, _out)
  gb_identifier(isoxml)
  gb_library_identifier(isoxml)
  gb_equivalence(isoxml)
end

#docid1(isoxml, _out) ⇒ Object



128
129
130
131
132
133
134
135
136
137
# File 'lib/isodoc/gb/metadata.rb', line 128

def docid1(isoxml, _out)
  dn = docnumber(isoxml)
  docstatus = get[:stage]
  if docstatus
    abbr = stage_abbrev(docstatus.to_s, isoxml.at(ns("//status/iteration")),
                        isoxml.at(ns("//version/draft")))
    (docstatus.to_i < 60) && dn = abbr + " " + dn
  end
  set(:docnumber, dn)
end

#docstatus(isoxml, _out) ⇒ Object



117
118
119
120
121
122
123
124
125
126
# File 'lib/isodoc/gb/metadata.rb', line 117

def docstatus(isoxml, _out)
  docstatus = isoxml.at(ns("//status/stage"))
  if docstatus
    set(:stage, docstatus.text.to_i)
    abbr = stage_abbrev_cn(docstatus.text, isoxml.at(ns("//status/iteration")),
                           isoxml.at(ns("//version/draft")))
    set(:stageabbr, abbr)
    set(:status, STATUS_CSS[docstatus.text.to_sym])
  end
end

#gb_equivalence(isoxml) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/isodoc/gb/metadata.rb', line 149

def gb_equivalence(isoxml)
  isostdid = isoxml.at(ns("#{ISO_STD_XPATH}/docidentifier")) || return
  set(:isostandard, isostdid.text)
  isostdtitle = isoxml.at(ns("#{ISO_STD_XPATH}/title"))
  set(:isostandardtitle, isostdtitle.text) if isostdtitle
  eq = isoxml.at(ns("//bibdata/relation/@type"))
  case eq.text
  when "equivalent" then set(:gbequivalence, "MOD")
  when "nonequivalent" then set(:gbequivalence, "NEQ")
  when "identical" then set(:gbequivalence, "IDT")
  end
end

#gb_identifier(isoxml) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/isodoc/gb/metadata.rb', line 162

def gb_identifier(isoxml)
  scope = isoxml.at(ns("//gbscope"))&.text || "national"
  mandate = isoxml.at(ns("//gbmandate"))&.text || "mandatory"
  prefix = isoxml.at(ns("//gbprefix"))&.text || "XXX"
  docyear = isoxml&.at(ns("//copyright/from"))&.text
  issuer = isoxml&.at(ns("//bibdata/contributor[role/@type = 'issuer']/"\
                         "organization/name"))&.text || "GB"
  @agencies = GbAgencies::Agencies.new(@lang, @labels, issuer)
  #set(:docidentifier, @agencies.docidentifier(scope, prefix, mandate, docyear, get[:docnumber]))
  set(:docidentifier, @agencies.docidentifier(nil, nil, nil, docyear, get[:docnumber]))
  set(:issuer, issuer)
  set(:standard_class, @agencies.standard_class(scope, prefix, mandate))
  set(:standard_agency, @agencies.standard_agency(scope, prefix, mandate))
  if scope == "local"
    set(:gbprefix, "DB")
    set(:gblocalcode, prefix)
  else
    set(:gbprefix, prefix)
  end 
  set(:gbscope, scope)
end

#gb_library_identifier(isoxml) ⇒ Object



196
197
198
199
200
201
202
203
204
205
# File 'lib/isodoc/gb/metadata.rb', line 196

def gb_library_identifier(isoxml)
  ics = []
  ccs = []
  isoxml.xpath(ns("//bibdata/ics/code")).each { |i| ics << i.text }
  isoxml.xpath(ns("//bibdata/ccs")).each { |i| ccs << i.text }
  p = isoxml.at(ns("//bibdata/plannumber"))
  set(:libraryid_ics, ics.empty? ? "XXX" : ics.join(", "))
  set(:libraryid_ccs, ccs.empty? ? "XXX" : ccs.join(", "))
  set(:libraryid_plan, p ? p.text : "XXX")
end

#part_label(partnumber, lang) ⇒ Object



207
208
209
210
211
212
# File 'lib/isodoc/gb/metadata.rb', line 207

def part_label(partnumber, lang)
  case lang
  when "en" then "Part #{partnumber}"
  when "zh" then "#{partnumber}部分"
  end
end

#set_doctitleObject



37
38
39
40
41
42
43
44
45
# File 'lib/isodoc/gb/metadata.rb', line 37

def set_doctitle
  if @lang == "zh"
    set(:doctitle, get[:docmaintitlezh] + 
                 get[:docsubtitlezh] + get[:docparttitlezh])
  else
    set(:doctitle, get[:docmaintitleen] + 
                 get[:docsubtitleen] + get[:docparttitleen])
  end
end

#stage_abbrev(stage, iter, draft) ⇒ Object



102
103
104
105
106
107
# File 'lib/isodoc/gb/metadata.rb', line 102

def stage_abbrev(stage, iter, draft)
  stage = STAGE_ABBRS[stage.to_sym] || "??"
  stage += iter.text if iter
  stage = "Pre" + stage if draft&.text =~ /^0\./
  stage
end

#stage_abbrev_cn(stage, iter, draft) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/isodoc/gb/metadata.rb', line 109

def stage_abbrev_cn(stage, iter, draft)
  return stage_abbrev(stage, iter, draft) if @lang != "zh"
  stage = STAGE_ABBRS_CN[stage.to_sym] || "??"
  stage = "#{iter.text.to_i.localize(:zh).spellout}#{stage}" if iter
  stage = "Pre" + stage if draft&.text =~ /^0\./
  stage
end

#standard_logo(gbprefix) ⇒ Object



184
185
186
187
188
189
190
191
192
193
194
# File 'lib/isodoc/gb/metadata.rb', line 184

def (gbprefix)
  return nil unless gbprefix
  case gbprefix.downcase
  when "db" then "gb-standard-db"
  when "gb" then "gb-standard-gb"
  when "gjb" then "gb-standard-gjb"
  when "gm" then "gb-standard-gm"
  when "jjf" then "gb-standard-jjf"
  when "zb" then "gb-standard-zb"
  end
end

#subtitle(isoxml, _out) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/isodoc/gb/metadata.rb', line 47

def subtitle(isoxml, _out)
  intro = isoxml.at(ns("//title-intro[@language='en']"))
  main = isoxml.at(ns("//title-main[@language='en']"))
  part = isoxml.at(ns("//title-part[@language='en']"))
  partnumber = isoxml.at(ns("//project-number/@part"))
  intro.nil? || set(:docmaintitleen, intro.text + "&mdash;")
  main.nil? || set(:docsubtitleen, main.text)
  partnum = partnumber ? "#{part_label(partnumber, 'en')}: " : ""
  part.nil? || set(:docparttitleen,
                            "&mdash;#{partnum} #{part.text}")
  set_doctitle
end

#title(isoxml, _out) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/isodoc/gb/metadata.rb', line 25

def title(isoxml, _out)
  intro = isoxml.at(ns("//title-intro[@language='zh']"))
  main = isoxml.at(ns("//title-main[@language='zh']"))
  part = isoxml.at(ns("//title-part[@language='zh']"))
  partnumber = isoxml.at(ns("//project-number/@part"))
  intro.nil? || set(:docmaintitlezh, intro.text + "&nbsp;")
  main.nil? || set(:docsubtitlezh, main.text)
  partnum = partnumber ? "#{part_label(partnumber, 'zh')}:" : ""
  part.nil? || set(:docparttitlezh,
                            "&nbsp;#{partnum}#{part.text}")
end