asciidoctor-gb 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,356 +0,0 @@
1
- module IsoDoc
2
- module Gb
3
- class Agencies
4
- def initialize(lang, labels, issuer)
5
- @lang = lang
6
- @labels = labels
7
- @issuer = issuer
8
- end
9
-
10
- SECTOR = { "zh" => {
11
- AQ: { industry: "安全生产", admin: "国家安全生产管理局" },
12
- BB: { industry: "包装", admin: "国家发改委" },
13
- CB: { industry: "船舶", admin: "国防科学工业委员会" },
14
- CH: { industry: "测绘", admin: "国家测绘局" },
15
- CJ: { industry: "城镇建设", admin: "建设部" },
16
- CY: { industry: "新闻出版", admin: "国家新闻出版总署" },
17
- DA: { industry: "档案", admin: "国家档案局" },
18
- DB: { industry: "地震", admin: "中国地震局" },
19
- DL: { industry: "电力", admin: "国家发改委" },
20
- DZ: { industry: "地质矿产", admin: "国土资源部" },
21
- EJ: { industry: "核工业", admin: "国防科学工业委员会" },
22
- FZ: { industry: "纺织", admin: "国家发改委" },
23
- GA: { industry: "公共安全", admin: "公安部" },
24
- GH: { industry: "供销", admin: "中华全国供销合作总社" },
25
- GM: { industry: "密码", admin: "国家密码管理局" },
26
- GY: { industry: "广播电影电视", admin: "国家广播电影电视总局" },
27
- HB: { industry: "航空", admin: "国防科学工业委员会" },
28
- HG: { industry: "化工", admin: "国家发改委" },
29
- HJ: { industry: "环境保护", admin: "国家环境保护总局" },
30
- HS: { industry: "海关", admin: "海关总署" },
31
- HY: { industry: "海洋", admin: "国家海洋局" },
32
- JB: { industry: "机械", admin: "国家发改委" },
33
- JC: { industry: "建材", admin: "国家发改委" },
34
- JG: { industry: "建筑工业", admin: "建设部" },
35
- JR: { industry: "金融", admin: "中国人民银行" },
36
- JT: { industry: "交通", admin: "交通部" },
37
- JY: { industry: "教育", admin: "教育部" },
38
- LB: { industry: "旅游", admin: "国家旅游局" },
39
- LD: { industry: "劳动和劳动安全", admin: "劳动和社会保障部" },
40
- LS: { industry: "粮食", admin: "国家粮食局" },
41
- LY: { industry: "林业", admin: "国家林业局" },
42
- MH: { industry: "民用航空", admin: "中国民航管理总局" },
43
- MT: { industry: "煤炭", admin: "国家发改委" },
44
- MZ: { industry: "民政", admin: "民政部" },
45
- NY: { industry: "农业", admin: "农业部" },
46
- QB: { industry: "轻工", admin: "国家发改委" },
47
- QC: { industry: "汽车", admin: "国家发改委" },
48
- QJ: { industry: "航天", admin: "国防科学工业委员会" },
49
- QX: { industry: "气象", admin: "中国气象局" },
50
- SB: { industry: "国内贸易", admin: "商务部" },
51
- SC: { industry: "水产", admin: "农业部" },
52
- SH: { industry: "石油化工", admin: "国家发改委" },
53
- SJ: { industry: "电子", admin: "信息产业部" },
54
- SL: { industry: "水利", admin: "水利部" },
55
- SN: { industry: "商检", admin: "国家质量监督检验检疫总局" },
56
- SY: { industry: "石油天然气", admin: "国家发改委" },
57
- TB: { industry: "铁道", admin: "铁道部" },
58
- TD: { industry: "土地管理", admin: "国土资源部" },
59
- TJ: { industry: "铁道交通", admin: "铁道部标准所" },
60
- TY: { industry: "体育", admin: "国家体育总局" },
61
- WB: { industry: "物资管理", admin: "国家发改委" },
62
- WH: { industry: "文化", admin: "文化部" },
63
- WJ: { industry: "兵工民品", admin: "国防科学工业委员会" },
64
- WM: { industry: "外经贸", admin: "外经贸部科技司" },
65
- WS: { industry: "卫生", admin: "卫生部" },
66
- WW: { industry: "文物保护", admin: "国家文物局" },
67
- XB: { industry: "稀土", admin: "国家发改委稀土办公室" },
68
- YB: { industry: "黑色冶金", admin: "国家发改委" },
69
- YC: { industry: "烟草", admin: "国家烟草专卖局" },
70
- YD: { industry: "通信", admin: "信息产业部" },
71
- YS: { industry: "有色冶金", admin: "国家发改委" },
72
- YY: { industry: "医药", admin: "国家食品药品监督管理局" },
73
- YZ: { industry: "邮政", admin: "国家邮政局" },
74
- ZY: { industry: "中医药", admin: "国家中医药管理局" },
75
- },
76
- "en" => {
77
- AQ: { industry: "Production Safety", admin: "State Administration of Work Safety" },
78
- BB: { industry: "Packaging", admin: "China National Packaging Industry Corporation" },
79
- CB: { industry: "Ships", admin: "National Defense Commission" },
80
- CH: { industry: "Surveying and Mapping", admin: "National Bureau of Surveying and Mapping" },
81
- CJ: { industry: "Town Construction", admin: "Ministry of Construction" },
82
- CY: { industry: "News Publishing", admin: "State Press and Publication Administration" },
83
- DA: { industry: "Archiving", admin: "National Archival Bureau" },
84
- DB: { industry: "Seismology", admin: "National Seismological Bureau" },
85
- DL: { industry: "Electricity", admin: "State Economic and Trade Commission" },
86
- DZ: { industry: "Geological and Mineral Products", admin: "Ministry of Land and Resources" },
87
- EJ: { industry: "Nuclear Industry", admin: "National Defense Commission" },
88
- FZ: { industry: "Textile", admin: "State Economic and Trade Commission" },
89
- GA: { industry: "Public Safety", admin: "Ministry of Public Security" },
90
- GH: { industry: "Supply and Marketing", admin: "China Federation of Supply and Marketing Cooperatives" },
91
- GM: { industry: "Cryptography", admin: "State Administration Of Cryptography" },
92
- GY: { industry: "Radio, Film and Television", admin: "State Administration of Radio, Film and Television" },
93
- HB: { industry: "Aviation", admin: "National Defense Commission" },
94
- HG: { industry: "Chemical Industry", admin: "State Economic and Trade Commission" },
95
- HJ: { industry: "Environmental Protection", admin: "State Environmental Protection Administration" },
96
- HS: { industry: "Customs", admin: "General Administration of Customs" },
97
- HY: { industry: "Oceanography", admin: "State Oceanic Administration" },
98
- JB: { industry: "Mechanical Engineering", admin: "State Economic and Trade Commission" },
99
- JC: { industry: "Building Materials", admin: "State Economic and Trade Commission" },
100
- JG: { industry: "Construction Industry", admin: "Ministry of Construction" },
101
- JR: { industry: "Financial", admin: "People’s Bank of China" },
102
- JT: { industry: "Traffic", admin: "Ministry of Communications" },
103
- JY: { industry: "Education", admin: "Ministry of Education" },
104
- LB: { industry: "Tourism", admin: "National Tourism Bureau" },
105
- LD: { industry: "Labor and Work Safety", admin: "Ministry of Labor and Social Security" },
106
- LS: { industry: "Food", admin: "National Food Administration" },
107
- LY: { industry: "Forestry", admin: "State Forestry Administration" },
108
- MH: { industry: "Civil Aviation", admin: "Civil Aviation Administration" },
109
- MT: { industry: "Coal", admin: "State Economic and Trade Commission" },
110
- MZ: { industry: "Civil Affairs", admin: "Ministry of Civil Affairs" },
111
- NY: { industry: "Agriculture", admin: "Ministry of Agriculture" },
112
- QB: { industry: "Light Industry", admin: "State Economic and Trade Commission" },
113
- QC: { industry: "Automotive", admin: "State Economic and Trade Commission" },
114
- QJ: { industry: "Aerospace", admin: "National Defense Commission" },
115
- QX: { industry: "Meteorological", admin: "China Meteorological Administration" },
116
- SB: { industry: "Domestic Business", admin: "Ministry of Commerce" },
117
- SC: { industry: "Aquatic Products", admin: "Ministry of Agriculture" },
118
- SH: { industry: "Petrochemical", admin: "State Economic and Trade Commission" },
119
- SJ: { industry: "Electronics", admin: "Ministry of Information Industry" },
120
- SL: { industry: "Water Resources", admin: "Ministry of Water Resources" },
121
- SN: { industry: "Inspection", admin: "General Administration of Quality Supervision, Inspection and Quarantine" },
122
- SY: { industry: "Natural Gas", admin: "State Economic and Trade Commission" },
123
- TB: { industry: "Rail Transport", admin: "Ministry of Railways" },
124
- TD: { industry: "Land Management", admin: "Ministry of Land and Resources" },
125
- TJ: { industry: "Railway Traffic", admin: "Ministry of Railways Standards" },
126
- TY: { industry: "Sports", admin: "National Department of Sport" },
127
- WB: { industry: "Materials Management", admin: "State Economic and Trade Commission" },
128
- WH: { industry: "Culture", admin: "Ministry of Culture" },
129
- WJ: { industry: "Ordnance", admin: "National Defense Commission" },
130
- WM: { industry: "Foreign Trade", admin: "Ministry of Foreign Trade and Economic Cooperation" },
131
- WS: { industry: "Health", admin: "Ministry of Health" },
132
- WW: { industry: "Cultural Relics Protection", admin: "National Heritage Board" },
133
- XB: { industry: "Rare Earths", admin: "State Planning Commission Rare Earths Office" },
134
- YB: { industry: "Ferrous Metallurgy", admin: "State Economic and Trade Commission" },
135
- YC: { industry: "Tobacco", admin: "State Tobacco Monopoly Bureau" },
136
- YD: { industry: "Communication", admin: "Ministry of Information Industry" },
137
- YS: { industry: "Non-Ferrous Metallurgy", admin: "State Economic and Trade Commission" },
138
- YY: { industry: "Medicine", admin: "State Food and Drug Administration" },
139
- YZ: { industry: "Postal", admin: "State Post Office" },
140
- ZY: { industry: "Chinese Medicine", admin: "State Administration of Traditional Chinese Medicine" },
141
- }
142
- }.freeze
143
-
144
- NATIONAL = {
145
- "zh" => {
146
- GB: { name: "中华人民共和国国家标准",
147
- admin: ["中华人民共和国国家质量监督检验检疫总局", "中国国家标准化管理委员会"] },
148
- "GB/T": { name: "中华人民共和国国家标准",
149
- admin: ["中华人民共和国国家质量监督检验检疫总局", "中国国家标准化管理委员会"] },
150
- "GB/Z": { name: "中华人民共和国国家标准化指导性技术文件",
151
- admin: ["中华人民共和国国家质量监督检验检疫总局", "中国国家标准化管理委员会"] },
152
- GBZ: { name: "中华人民共和国国家职业卫生标准", admin: "中华人民共和国卫生部" },
153
- GJB: { name: "中华人民共和国国家军用标准", admin: "中国人民解放军装备总部" },
154
- GBn: { name: "中华人民共和国国家内部标准", admin: "" },
155
- GHZB: { name: "中华人民共和国国家环境质量标准", admin: "" }, GWKB: { name: "中华人民共和国国家环境保护标准", admin: "环境保护部" },
156
- GWPB: { name: "中华人民共和国国家污染物排放标准", admin: "" },
157
- JJF: { name: "中华人民共和国国家计量技术规范", admin: "中华人民共和国国家质量监督检验检疫总局" },
158
- JJG: { name: "中华人民共和国国家计量检定规程", admin: "中华人民共和国国家质量监督检验检疫总局" },
159
- },
160
- "en" => {
161
- GB: { name: "National standard",
162
- admin: "General Administration of Quality Supervision, Inspection and Quarantine; Standardization Administration of China" },
163
- "GB/T": { name: "National standard (Recommended)",
164
- admin: "General Administration of Quality Supervision, Inspection and Quarantine; Standardization Administration of China" },
165
- "GB/Z": { name: "Standardized guidelines",
166
- admin: "General Administration of Quality Supervision, Inspection and Quarantine; Standardization Administration of China" },
167
- GBZ: { name: "National occupational health standards", admin: "Ministry of Health" },
168
- GJB: { name: "National military standards", admin: "Chinese People’s Liberation Army Equipment Headquarters" },
169
- GBn: { name: "National internal standards", admin: "" },
170
- GHZB: { name: "National environmental quality standards", admin: "" }, GWKB: { name: "National Environmental Protection Standards", admin: "Ministry of Environmental Protection" },
171
- GWPB: { name: "National pollutant discharge standards", admin: "" },
172
- JJF: { name: "National calibration specifications", admin: "General Administration of Quality Supervision, Inspection and Quarantine" },
173
- JJG: { name: "National calibration verification regulations", admin: "General Administration of Quality Supervision, Inspection and Quarantine" },
174
- }
175
- }.freeze
176
-
177
- LOCAL = {
178
- "zh" => {
179
- "11": "北京市",
180
- "12": "天津市",
181
- "13": "河北省",
182
- "14": "山西省",
183
- "15": "内蒙古自治区",
184
- "21": "辽宁省",
185
- "22": "吉林省",
186
- "23": "黑龙江省",
187
- "31": "上海市",
188
- "32": "江苏省",
189
- "33": "浙江省",
190
- "34": "安徽省",
191
- "35": "福建省",
192
- "36": "江西省",
193
- "37": "山东省",
194
- "41": "河南省",
195
- "42": "湖北省",
196
- "43": "湖南省",
197
- "44": "广东省",
198
- "45": "广西壮族自治区",
199
- "46": "海南省",
200
- "50": "重庆市",
201
- "51": "四川省",
202
- "52": "贵州省",
203
- "53": "云南省",
204
- "54": "西藏自治区",
205
- "61": "陕西省",
206
- "62": "甘肃省",
207
- "63": "青海省",
208
- "64": "宁夏回族自治区",
209
- "65": "新疆维吾尔自治区",
210
- "71": "台湾省",
211
- "81": "香港特别行政区",
212
- "82": "澳门特别行政区",
213
- },
214
- "en" => {
215
- "11": "Beijing City",
216
- "12": "Tianjin",
217
- "13": "Hebei Province",
218
- "14": "Shanxi Province",
219
- "15": "Inner Mongolia Autonomous Region",
220
- "21": "Liaoning Province",
221
- "22": "Jilin Province",
222
- "23": "Heilongjiang Province",
223
- "31": "Shanghai",
224
- "32": "Jiangsu Province",
225
- "33": "Zhejiang Province",
226
- "34": "Anhui Province",
227
- "35": "Fujian Province",
228
- "36": "Jiangxi Province",
229
- "37": "Shandong Province",
230
- "41": "Henan Province",
231
- "42": "Hubei Province",
232
- "43": "Hunan Province",
233
- "44": "Guangdong Province",
234
- "45": "Guangxi Zhuang Autonomous Region",
235
- "46": "Hainan",
236
- "50": "Chongqing",
237
- "51": "Sichuan Province",
238
- "52": "Guizhou Province",
239
- "53": "Yunnan Province",
240
- "54": "Tibet Autonomous Region",
241
- "61": "Shaanxi Province",
242
- "62": "Gansu Province",
243
- "63": "Qinghai Province",
244
- "64": "Ningxia Hui Autonomous Region",
245
- "65": "Xinjiang Uygur Autonomous Region",
246
- "71": "Taiwan Province",
247
- "81": "Hong Kong Special Administrative Region",
248
- "82": "Macao Special Administrative Region",
249
- }
250
- }.freeze
251
-
252
- def gb_mandate_suffix(prefix, mandate)
253
- if prefix == "GB"
254
- prefix += "/T" if mandate == "recommended"
255
- prefix += "/Z" if mandate == "guide"
256
- end
257
- prefix
258
- end
259
-
260
- def mandate_suffix(prefix, mandate)
261
- prefix += "/T" if mandate == "recommended"
262
- prefix += "/Z" if mandate == "guide"
263
- prefix
264
- end
265
-
266
- def standard_class(scope, prefix, mandate)
267
- case scope
268
- when "national"
269
- NATIONAL&.dig(@lang, gb_mandate_suffix(prefix, mandate).to_sym,
270
- :name) || "XXXX"
271
- when "sector"
272
- "#{@labels["PRC"]}#{SECTOR&.dig(@lang, prefix.to_sym,
273
- :industry) || 'XXXX'}#{@labels["industry_standard"]}"
274
- when "local"
275
- "#{LOCAL&.dig(@lang, prefix.to_sym) || 'XXXX'}#{@labels["local_standard"]}"
276
- when "enterprise"
277
- #issuer = get_metadata[:issuer]
278
- "#{@issuer}#{@labels["enterprise_standard"]}"
279
- when "social-group" then @labels["social_standard"]
280
- when "professional" then "PROFESSIONAL STANDARD" # TODO
281
- end
282
- end
283
-
284
- def standard_agency1(scope, prefix, mandate)
285
- case scope
286
- when "national"
287
- ret = NATIONAL&.dig(@lang, gb_mandate_suffix(prefix, mandate).to_sym,
288
- :admin) || nil
289
- ret = ret.join(" ") if ret && ret.is_a?(Array)
290
- ret
291
- when "sector"
292
- SECTOR&.dig(@lang, prefix.to_sym, :admin) || nil
293
- when "local"
294
- LOCAL&.dig(@lang, prefix.to_sym) || nil
295
- when "enterprise", "social-group"
296
- #get_metadata[:issuer] || nil
297
- @issuer || nil
298
- when "professional" then "PROFESSIONAL STANDARD" # TODO
299
- end
300
- end
301
-
302
- def standard_agency(scope, prefix, mandate)
303
- case scope
304
- when "national"
305
- NATIONAL&.dig(@lang, gb_mandate_suffix(prefix, mandate).to_sym,
306
- :admin) || nil
307
- when "sector"
308
- SECTOR&.dig(@lang, prefix.to_sym, :admin) || nil
309
- when "local"
310
- "#{LOCAL&.dig(@lang, prefix.to_sym) || 'XXXX'}#{@labels["local_issuer"]}"
311
- when "enterprise", "social-group"
312
- #get_metadata[:issuer]
313
- @issuer
314
- when "professional" then "PROFESSIONAL STANDARD" # TODO
315
- end
316
- end
317
-
318
- SCOPEPFX = {
319
- :local => "DB",
320
- "social-group".to_sym => "T",
321
- :enterprise => "Q",
322
- }.freeze
323
-
324
- def docidentifier(scope, prefix, mandate, docyear, docnum)
325
- dn = case scope
326
- when "local"
327
- "#{SCOPEPFX[scope.to_sym]}#{mandate_suffix(prefix, mandate)}/"\
328
- "#{docnum}".gsub(%r{/([TZ])/}, "/\\1 ")
329
- when "social-group", "enterprise"
330
- "#{mandate_suffix(SCOPEPFX[scope.to_sym], mandate)}/"\
331
- "#{prefix} #{docnum}"
332
- else
333
- "#{mandate_suffix(prefix, mandate)} #{docnum}"
334
- end
335
- dn += "—#{docyear}" if docyear
336
- dn
337
- end
338
-
339
- def gbtype_validate(root)
340
- scope = root.at("//gbscope")&.text
341
- prefix = root.at("//gbprefix")&.text
342
- case scope
343
- when "national"
344
- NATIONAL.dig(@lang, prefix.to_sym) ||
345
- warn("GB: #{prefix} is not a recognised national prefix")
346
- when "sector"
347
- SECTOR.dig(@lang, prefix.to_sym) ||
348
- warn("GB: #{prefix} is not a recognised sector prefix")
349
- when "local"
350
- LOCAL.dig(@lang, prefix.to_sym) ||
351
- warn("GB: #{prefix} is not a recognised local prefix")
352
- end
353
- end
354
- end
355
- end
356
- end