metanorma-jis 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a9602ab994ed2bd305740c06c8e905e6a006cc61f90a86eaae5636382029592
4
- data.tar.gz: 720ccbdc20eef80020f6360d049655b8b3d50a7341290eca697f126e7b8cf1db
3
+ metadata.gz: 8bcd50e7099ae02c6427bbca496f824f9429ba102e0d3b8df1bdb2f2fd6cb9a2
4
+ data.tar.gz: 760abf62f4c69e4f73f8fa9e2bfc696e431b6fc4859b79f103e4595d6883bb3e
5
5
  SHA512:
6
- metadata.gz: c9aba7ea31bf9d5d50c2c1a16cb7e430287c11440ed7bf636483c077830b494d782c1b858649f065031180ebcbc12f745b887628f6ca312794f1de8afe9655f6
7
- data.tar.gz: cb1d5e2653e717b942d10d6d83211a57c4343e30989f7f023dcb9dc0eee3ec8ef2011a68e05b993344779031f7c53e3e60714fd6017ae98979dd34a7c0608080
6
+ metadata.gz: d1128ad3d108ac316a8d4c324c69b2fa5328838b84a1ff4b59f7b01ab79464c7946839c151c1a0749c52bc4da406c5ab820f7be2aefb43a06c36464757ebf020
7
+ data.tar.gz: c06c9323c1e2af9c1fe73c5b2e43c68dcb81efebb4004bc8c6f88959b2bfc43cc3989366c92242eab460873e137419e7efa83c6b5732f2a33ee71ea9f46f0168
data/Gemfile CHANGED
@@ -2,11 +2,14 @@ Encoding.default_external = Encoding::UTF_8
2
2
  Encoding.default_internal = Encoding::UTF_8
3
3
 
4
4
  source "https://rubygems.org"
5
+ git_source(:github) { |repo| "https://github.com/#{repo}" }
5
6
 
6
- # Specify your gem's dependencies in gemspec
7
- gemspec
7
+ group :development, :test do
8
+ gem "rspec"
9
+ end
8
10
 
9
11
  if File.exist? "Gemfile.devel"
10
12
  eval File.read("Gemfile.devel"), nil, "Gemfile.devel" # rubocop:disable Security/Eval
11
13
  end
12
14
 
15
+ gemspec
@@ -7,29 +7,49 @@ module Metanorma
7
7
  super.merge("Japanese Industrial Standards" => "JIS")
8
8
  end
9
9
 
10
- def home_agency
10
+ def default_publisher
11
11
  "JIS"
12
12
  end
13
13
 
14
- # Like the ISO code, but multilingual
14
+ # # Like the ISO code, but multilingual
15
+ # def metadata_author(node, xml)
16
+ # metadata_contrib_sdo(node, xml, JIS_HASH,
17
+ # { role: "author", sourcerole: "publisher" })
18
+ # node.attr("doctype") == "expert-commentary" and
19
+ # personal_author(node, xml)
20
+ # end
21
+
15
22
  def metadata_author(node, xml)
16
- metadata_contrib_sdo(node, xml, JIS_HASH,
17
- { role: "author", sourcerole: "publisher" })
23
+ org_contributor(node, xml,
24
+ { source: ["publisher", "pub"], role: "author",
25
+ default: JIS_HASH })
18
26
  node.attr("doctype") == "expert-commentary" and
19
27
  personal_author(node, xml)
20
28
  end
21
29
 
30
+ # def metadata_publisher(node, xml)
31
+ # metadata_contrib_sdo(node, xml, JIS_HASH,
32
+ # { role: "publisher", sourcerole: "publisher" })
33
+ # metadata_contrib_sdo(node, xml, nil,
34
+ # { role: "authorizer",
35
+ # sourcerole: "investigative-organization",
36
+ # desc: "Investigative organization" })
37
+ # metadata_contrib_sdo(node, xml, nil,
38
+ # { role: "authorizer",
39
+ # sourcerole: "investigative-committee",
40
+ # desc: "Investigative committee" })
41
+ # end
42
+
22
43
  def metadata_publisher(node, xml)
23
- metadata_contrib_sdo(node, xml, JIS_HASH,
24
- { role: "publisher", sourcerole: "publisher" })
25
- metadata_contrib_sdo(node, xml, nil,
26
- { role: "authorizer",
27
- sourcerole: "investigative-organization",
28
- desc: "Investigative organization" })
29
- metadata_contrib_sdo(node, xml, nil,
30
- { role: "authorizer",
31
- sourcerole: "investigative-committee",
32
- desc: "Investigative committee" })
44
+ [{ source: ["publisher", "pub"], role: "publisher", default: JIS_HASH },
45
+ { role: "authorizer",
46
+ source: ["investigative-organization"],
47
+ desc: "Investigative organization" },
48
+ { role: "authorizer",
49
+ source: ["investigative-committee"],
50
+ desc: "Investigative committee" }].each do |o|
51
+ org_contributor(node, xml, o)
52
+ end
33
53
  end
34
54
 
35
55
  LANGS = %w(ja en).freeze
@@ -37,56 +57,111 @@ module Metanorma
37
57
  JIS_HASH =
38
58
  { "ja" => "日本工業規格", "en" => "Japanese Industrial Standards" }.freeze
39
59
 
40
- def metadata_contrib_sdo(node, xml, default_value, opt)
41
- pub, default = metadata_contrib_extract(node, opt[:sourcerole], default_value)
42
- metadata_contrib_sdo_build(node, xml, pub, default, opt)
60
+ # def metadata_contrib_sdo(node, xml, default_value, opt)
61
+ # pub, default = metadata_contrib_extract(node, opt[:sourcerole], default_value)
62
+ # metadata_contrib_sdo_build(node, xml, pub, default, opt)
63
+ # end
64
+ #
65
+ # def metadata_contrib_sdo_build(node, xml, pub, default, opt)
66
+ # pub&.each do |p|
67
+ # xml.contributor do |c|
68
+ # c.role type: opt[:role] do |r|
69
+ # opt[:desc] and r.description opt[:desc]
70
+ # end
71
+ # c.organization do |a|
72
+ # organization(a, p, opt[:role] == "publisher", node, default)
73
+ # end
74
+ # end
75
+ # end
76
+ # end
77
+ #
78
+ # def metadata_contrib_extract(node, role, default_value)
79
+ # pub, default = multiling_docattr_csv(node, role, LANGS, default_value)
80
+ # a = node.attr("#{role}-abbr") and abbr = a # one abbrev for all languages
81
+ # [pub&.map { |p| { name: p, abbr: abbr } }, default]
82
+ # end
83
+ #
84
+ # def multiling_docattr(node, attr, langs)
85
+ # ret = node.attr(attr) and return ret
86
+ # ret = langs.each_with_object({}).each do |l, m|
87
+ # x = node.attr("#{attr}-#{l}") and m[l] = x
88
+ # end.compact
89
+ # ret.empty? and return nil
90
+ # ret
91
+ # end
92
+ #
93
+ # def multiling_docattr_csv(node, attr, langs, default)
94
+ # ret = multiling_docattr(node, attr, langs)
95
+ # not_found = ret.nil?
96
+ # ret ||= default
97
+ # ret &&= if ret.is_a?(Hash) then interleave_multiling_docattr(ret)
98
+ # else csv_split(ret)
99
+ # end
100
+ # [ret, not_found]
101
+ # end
102
+ #
103
+ # # TODO abort if CSV count different between different languages
104
+ # def interleave_multiling_docattr(ret)
105
+ # h = ret.transform_values { |v| csv_split(v) }
106
+ # h.each_with_object([]) do |(k, v), m|
107
+ # v.each_with_index do |v1, i|
108
+ # m[i] ||= {}
109
+ # m[i][k] = v1
110
+ # end
111
+ # end
112
+ # end
113
+
114
+ def org_organization(node, xml, org)
115
+ organization(xml, { name: org[:name], abbr: org[:abbr] }.compact,
116
+ node, !multiling_docattr(node, "publisher", "", LANGS))
117
+ org_address(org, xml)
118
+ org_logo(xml, org[:logo])
43
119
  end
44
120
 
45
- def metadata_contrib_sdo_build(node, xml, pub, default, opt)
46
- pub&.each do |p|
47
- xml.contributor do |c|
48
- c.role type: opt[:role] do |r|
49
- opt[:desc] and r.description opt[:desc]
50
- end
51
- c.organization do |a|
52
- organization(a, p, opt[:role] == "publisher", node, default)
53
- end
121
+ def org_attrs_parse(node, opts)
122
+ source = opts[:source]&.detect { |s| node.attr(s) }
123
+ source ||= opts[:source]&.detect do |s|
124
+ LANGS.detect { |l| node.attr("#{s}-#{l}") }
54
125
  end
55
- end
126
+ org_attrs_simple_parse(node, opts, source) ||
127
+ org_attrs_complex_parse(node, opts, source)
56
128
  end
57
129
 
58
- def metadata_contrib_extract(node, role, default_value)
59
- pub, default = multiling_docattr_csv(node, role, LANGS, default_value)
60
- a = node.attr("#{role}-abbr") and abbr = a # one abbrev for all languages
61
- [pub&.map { |p| { name: p, abbr: abbr } }, default]
130
+ def org_attrs_complex_parse(node, opts, source)
131
+ i = 1
132
+ suffix = ""
133
+ ret = []
134
+ while multiling_docattr(node, source, suffix, LANGS)
135
+ ret << extract_org_attrs_complex(node, opts, source, suffix)
136
+ i += 1
137
+ suffix = "_#{i}"
138
+ end
139
+ ret
62
140
  end
63
141
 
64
- def multiling_docattr(node, attr, langs)
65
- ret = node.attr(attr) and return ret
142
+ def multiling_docattr(node, attr, suffix, langs)
143
+ ret = node.attr(attr + suffix) and return ret
66
144
  ret = langs.each_with_object({}).each do |l, m|
67
- x = node.attr("#{attr}-#{l}") and m[l] = x
145
+ x = node.attr("#{attr}-#{l}#{suffix}") and m[l] = x
68
146
  end.compact
69
147
  ret.empty? and return nil
70
148
  ret
71
149
  end
72
150
 
73
- def multiling_docattr_csv(node, attr, langs, default)
74
- ret = multiling_docattr(node, attr, langs)
75
- not_found = ret.nil?
76
- ret ||= default
77
- ret &&= if ret.is_a?(Hash) then interleave_multiling_docattr(ret)
78
- else csv_split(ret)
79
- end
80
- [ret, not_found]
151
+ def extract_org_attrs_complex(node, opts, source, suffix)
152
+ { name: multiling_docattr(node, source, suffix, LANGS),
153
+ role: opts[:role], desc: opts[:desc],
154
+ abbr: multiling_docattr(node, "#{source}-abbr", suffix, LANGS),
155
+ logo: multiling_docattr(node, "#{source}_logo", suffix, LANGS) }
156
+ .compact
157
+ .merge(extract_org_attrs_address(node, opts, suffix))
81
158
  end
82
159
 
83
- # TODO abort if CSV count different between different languages
84
- def interleave_multiling_docattr(ret)
85
- h = ret.transform_values { |v| csv_split(v) }
86
- h.each_with_object([]) do |(k, v), m|
87
- v.each_with_index do |v1, i|
88
- m[i] ||= {}
89
- m[i][k] = v1
160
+ def extract_org_attrs_address(node, opts, suffix)
161
+ %w(address phone fax email uri).each_with_object({}) do |a, m|
162
+ opts[:source]&.each do |s|
163
+ p = multiling_docattr(node, "#{s}-#{a}", suffix, LANGS) and
164
+ m[a.to_sym] = p
90
165
  end
91
166
  end
92
167
  end
@@ -104,37 +179,44 @@ module Metanorma
104
179
  end
105
180
  end
106
181
 
107
- def organization(xml, org, _is_pub, node = nil, default_org = nil)
108
- org.is_a?(Hash) or org = { name: org }
182
+ def organization(xml, org, node = nil, default_org = nil)
183
+ org.is_a?(Hash) && org[:name] or org = { name: org }
109
184
  abbrevs = org_abbrev
110
185
  name_str = org[:name].is_a?(Hash) ? org[:name]["en"] : org[:name]
111
186
  n = abbrevs.invert[org[:name]] and org = { name: n, abbr: org[:name] }
112
187
  multiling_noko_value(org[:name], "name", xml)
113
- default_org && a = multiling_docattr(node, "subdivision", LANGS) and
188
+ default_org && a = multiling_docattr(node, "subdivision", "", LANGS) and
114
189
  multiling_noko_value(a, "subdivision", xml)
115
190
  abbr = org[:abbr]
116
191
  abbr ||= org_abbrev[name_str]
117
192
  default_org && b = node.attr("subdivision-abbr") and abbr = b
118
193
  abbr and xml.abbreviation abbr
119
- # is_pub && node and org_address(node, org) # should refactor into struct, like abbr
120
194
  end
121
195
 
122
- def metadata_copyright(node, xml)
123
- pub, default = metadata_contrib_extract(node, "copyright-holder", nil)
124
- if default
125
- pub, default = metadata_contrib_extract(node, "publisher", JIS_HASH)
126
- end
196
+ # def metadata_copyright(node, xml)
197
+ # pub, default = metadata_contrib_extract(node, "copyright-holder", nil)
198
+ # if default
199
+ # pub, default = metadata_contrib_extract(node, "publisher", JIS_HASH)
200
+ # end
201
+ #
202
+ # pub&.each do |p|
203
+ # xml.copyright do |c|
204
+ # c.from (node.attr("copyright-year") || Date.today.year)
205
+ # c.owner do |owner|
206
+ # owner.organization do |o|
207
+ # organization(o, p, true, node, default)
208
+ # end
209
+ # end
210
+ # end
211
+ # end
212
+ # end
127
213
 
128
- pub&.each do |p|
129
- xml.copyright do |c|
130
- c.from (node.attr("copyright-year") || Date.today.year)
131
- c.owner do |owner|
132
- owner.organization do |o|
133
- organization(o, p, true, node, default)
134
- end
135
- end
136
- end
137
- end
214
+ def copyright_parse(node)
215
+ opt = { source: ["copyright-holder", "publisher", "pub"],
216
+ role: "publisher", default: JIS_HASH }
217
+ ret = org_attrs_parse(node, opt)
218
+ ret.empty? and ret = [{ name: "-" }]
219
+ ret
138
220
  end
139
221
 
140
222
  def title(node, xml)
@@ -1,6 +1,6 @@
1
1
  module Metanorma
2
2
  module JIS
3
- VERSION = "0.1.3".freeze
3
+ VERSION = "0.1.4".freeze
4
4
  end
5
5
  end
6
6
 
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.test_files = `git ls-files -- {spec}/*`.split("\n")
31
31
  spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
32
32
 
33
- spec.add_dependency "metanorma-iso", "~> 2.5.4"
33
+ spec.add_dependency "metanorma-iso", "~> 2.6.0"
34
34
  spec.add_dependency "pubid-jis"
35
35
 
36
36
  spec.add_development_dependency "debug"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-jis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-20 00:00:00.000000000 Z
11
+ date: 2023-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: metanorma-iso
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.5.4
19
+ version: 2.6.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.5.4
26
+ version: 2.6.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pubid-jis
29
29
  requirement: !ruby/object:Gem::Requirement