relaton-render 0.5.7 → 0.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0f0cf15017a8c117f7a8fde7567564f61138760cfeb89b506e5c2848ff6899d
4
- data.tar.gz: 2d5bdd64aeb924e67b2c4f823e60033a1a51018542deb4596f32533038919e00
3
+ metadata.gz: 4279b77e453986c5068226fd078df3c97746d9ebbbe04a0b1217eccb27804030
4
+ data.tar.gz: c2340eca6f974d0fca1f6120fb50d1092dc9159a7d658734e3f750cf149b6692
5
5
  SHA512:
6
- metadata.gz: 2f05f38566cf4f94bad2152db2cb2c71c0d2f2a63939c7bac0039fbaa0e21314aba6288640ec9a7c1248b6548342ba21ccff47e0b360902055ed1f026f52eabc
7
- data.tar.gz: e787ce6357bfd515b9d7a975027f798ec027fa2845a6495ea53c0c2032abb8e90f7881736bf1f0c947cf30e0b82e5aeb259ba9f9f20877823828cc6c3d987277
6
+ metadata.gz: f7ecf68117575c5b55b99bbad99a9eea91263ce61224253ee9149de113ce6edf66bd543dfb8d475a4ab4599572bd2701edc60c31576fa6d1475fb73cb63c2aff
7
+ data.tar.gz: c9a1452e1fb08dbc7d910a63b25b3e453919b5d3d1ce7cc0c943bf1adb3f6e6a9f6d638ca1be814a9ec836c77b2e6cc66be1a3be34f733cc2aedbfad45510df3
data/README.adoc CHANGED
@@ -155,14 +155,15 @@ drawn from the bibliographic item:
155
155
  | place | ./place | | Y |
156
156
  | publisher | ./contributor[role/@type = 'publisher']/organization/name | | Y |
157
157
  | distributor | ./contributor[role/@type = 'distributor']/organization/name | | Y |
158
+ | authorizer | ./contributor[role/@type = 'authorizer']/organization/name \| ./contributor[role/@type = 'publisher']/organization/name | | Y |
158
159
  | authoritative_identifier | ./docidentifier[not(@type = 'metanorma' or @type = 'ordinal' or @type = 'ISBN' or @type = 'ISSN' or @type = 'DOI')] | Y | |
159
160
  | other_identifier | ./docidentifier[@type = 'ISBN' or @type = 'ISSN' or @type = 'DOI'] | Y | | By default, each such identifier is prefixed with its type and colon
160
161
  | status | ./status | | | Rendering varies by flavour
161
162
  | uri | ./uri[@type = 'citation' or @type = 'uri' or @type = 'src' or true] | | | If multiples, prioritise language match. Always exclude DOI: that is not where the resource is available from
162
163
  | access_location | ./accessLocation | | Y |
163
164
  | extent | ./extent | Y | | Render with standard abbreviations for pp, vols, with n-dash, with delimiting of multiple locations
164
- | creatornames | ./contributor[role/@type = 'author'] \| ./contributor[role/@type = 'performer'] \| ./contributor[role/@type = 'adapter'] \| ./contributor[role/@type = 'translator'] \| ./contributor[role/@type = 'editor'] \| ./contributor[role/@type = 'distributor'] \| ./contributor | Y | | <<nametemplate,`nametemplate`>> applied to each name; joining template from internationalisation applied to multiple names
165
- | authorcite | ./contributor[role/@type = 'author'] \| ./contributor[role/@type = 'performer'] \| ./contributor[role/@type = 'adapter'] \| ./contributor[role/@type = 'translator'] \| ./contributor[role/@type = 'editor'] \| ./contributor[role/@type = 'distributor'] \| ./contributor | Y | | <<authorcitetemplate,`authorcitetemplate`>> applied to each name; joining template from internationalisation applied to multiple names
165
+ | creatornames | ./contributor[role/@type = 'author'] \| ./contributor[role/@type = 'performer'] \| ./contributor[role/@type = 'adapter'] \| ./contributor[role/@type = 'translator'] \| ./contributor[role/@type = 'editor'] \| ./contributor[role/@type = 'distributor'] \| ./contributor[role/@type = 'authorizer'] \| ./contributor | Y | | <<nametemplate,`nametemplate`>> applied to each name; joining template from internationalisation applied to multiple names
166
+ | authorcite | ./contributor[role/@type = 'author'] \| ./contributor[role/@type = 'performer'] \| ./contributor[role/@type = 'adapter'] \| ./contributor[role/@type = 'translator'] \| ./contributor[role/@type = 'editor'] \| ./contributor[role/@type = 'distributor'] \| ./contributor[role/@type = 'authorizer'] \| ./contributor | Y | | <<authorcitetemplate,`authorcitetemplate`>> applied to each name; joining template from internationalisation applied to multiple names
166
167
  | role | ./contributor[role/description] \| ./contributor[role/@type] | | |
167
168
  | date | ./date[@type = 'issued'] \| ./date[@type = 'circulated'] \| ./date | | Y |
168
169
  | date_updated | ./date[@type = 'updated'] | | Y |
@@ -17,7 +17,8 @@ module Relaton
17
17
 
18
18
  def name_fields_format(hash)
19
19
  [%i(creatornames creators), %i(host_creatornames host_creators),
20
- %i(publisher publisher_raw), %i(distributor distributor_raw)]
20
+ %i(publisher publisher_raw), %i(distributor distributor_raw),
21
+ %i(authorizer authorizer_raw)]
21
22
  .each do |k|
22
23
  hash[k[0]] = nameformat(hash[k[1]])
23
24
  end
@@ -62,8 +63,7 @@ module Relaton
62
63
 
63
64
  # TODO is not being i18n-alised
64
65
  def mediumformat(hash)
65
- return nil if hash.nil?
66
-
66
+ hash.nil? and return nil
67
67
  %w(content genre form carrier size scale).each_with_object([]) do |i, m|
68
68
  m << hash[i] if hash[i]
69
69
  m
@@ -81,8 +81,7 @@ module Relaton
81
81
  end
82
82
 
83
83
  def nameformat(names)
84
- return names if names.nil?
85
-
84
+ names.nil? and return names
86
85
  parts = %i(surname initials given middle nonpersonal)
87
86
  names_out = names.each_with_object({}) do |n, m|
88
87
  parts.each do |i|
@@ -94,8 +93,7 @@ module Relaton
94
93
  end
95
94
 
96
95
  def authorciteformat(names)
97
- return names if names.nil? || @r.authorcitetemplate.nil?
98
-
96
+ names.nil? || @r.authorcitetemplate.nil? and return names
99
97
  parts = %i(surname initials given middle nonpersonal)
100
98
  names_out = names.each_with_object({}) do |n, m|
101
99
  parts.each do |i|
@@ -107,9 +105,9 @@ module Relaton
107
105
  end
108
106
 
109
107
  def role_inflect(contribs, role)
110
- return nil if role.nil? || contribs.size.zero? ||
111
- %w(author publisher).include?(role)
112
-
108
+ role.nil? || contribs.size.zero? ||
109
+ %w(author publisher distributor
110
+ authorizer).include?(role) and return nil
113
111
  number = contribs.size > 1 ? "pl" : "sg"
114
112
  @r.i18n.get[role][number] || role
115
113
  end
@@ -134,9 +132,9 @@ module Relaton
134
132
  end
135
133
 
136
134
  def draftformat(num, _hash)
137
- return nil if num.nil?
138
- return nil if num.is_a?(Hash) && num[:status].nil? && num[:iteration].nil?
139
-
135
+ num.nil? ||
136
+ (num.is_a?(Hash) && num[:status].nil? &&
137
+ num[:iteration].nil?) and return nil
140
138
  @r.i18n.draft.sub(/%/, num)
141
139
  end
142
140
 
@@ -180,23 +178,16 @@ module Relaton
180
178
 
181
179
  def sizeformat1(key, val, hash)
182
180
  case key
183
- when "volume"
184
- hash[:volume_raw] = val
185
- hash[:volume] = pagevolformat(val, nil, "volume", true)
186
- when "issue"
187
- hash[:issue_raw] = val
188
- hash[:issue] = pagevolformat(val, nil, "issue", true)
189
- when "page"
190
- hash[:page_raw] = val
191
- hash[:page] = pagevolformat(val, nil, "page", true)
181
+ when "volume", "issue", "page"
182
+ hash["#{key}_raw".to_sym] = val
183
+ hash[key.to_sym] = pagevolformat(val, nil, key, true)
192
184
  when "data" then hash[:data] = val
193
185
  when "duration" then hash[:duration] = val
194
186
  end
195
187
  end
196
188
 
197
189
  def pagevolformat(value, value_raw, type, is_size)
198
- return nil if value.nil?
199
-
190
+ value.nil? and return nil
200
191
  num = "pl"
201
192
  if is_size
202
193
  value == "1" and num = "sg"
@@ -215,8 +206,7 @@ module Relaton
215
206
  end
216
207
 
217
208
  def dateformat(date, _hash)
218
- return nil if date.nil?
219
-
209
+ date.nil? and return nil
220
210
  %i(from to on).each do |k|
221
211
  date[k] = ::Relaton::Render::Date.new(date[k], renderer: @r).render
222
212
  end
@@ -224,20 +214,16 @@ module Relaton
224
214
  end
225
215
 
226
216
  def uriformat(uri)
227
- return nil if uri.nil? || uri.empty?
228
-
217
+ uri.nil? || uri.empty? and return nil
229
218
  "<link target='#{uri}'>#{uri}</link>"
230
219
  end
231
220
 
232
221
  private
233
222
 
234
223
  def tw_cldr_lang
235
- if @r.lang != "zh"
236
- @r.lang.to_sym
237
- elsif @r.script == "Hant"
238
- :"zh-tw"
239
- else
240
- :"zh-cn"
224
+ if @r.lang != "zh" then @r.lang.to_sym
225
+ elsif @r.script == "Hant" then :"zh-tw"
226
+ else :"zh-cn"
241
227
  end
242
228
  end
243
229
  end
@@ -30,10 +30,11 @@ module Relaton
30
30
 
31
31
  def simple_or_host_xml2hash(doc, host)
32
32
  { edition_raw: edition(doc, host), edition_num: edition_num(doc, host),
33
- medium_raw: medium(doc, host),
33
+ medium_raw: medium(doc, host), draft_raw: draft(doc, host),
34
34
  place_raw: place(doc, host), publisher_raw: publisher(doc, host),
35
35
  publisher_abbrev_raw: publisher_abbrev(doc, host),
36
- distributor_raw: distributor(doc, host), draft_raw: draft(doc, host),
36
+ authorizer_raw: authorizer(doc, host),
37
+ distributor_raw: distributor(doc, host),
37
38
  access_location: access_location(doc, host),
38
39
  date: date(doc, host), date_updated: date_updated(doc, host),
39
40
  date_accessed: date_accessed(doc, host) }
@@ -3,6 +3,7 @@ module Relaton
3
3
  class Parse
4
4
  def content(node)
5
5
  node.nil? and return node
6
+ node.content.is_a?(Array) and return node.content.map { |x| content(x) }
6
7
  node.content.strip
7
8
  end
8
9
 
@@ -74,7 +75,7 @@ module Relaton
74
75
  end
75
76
 
76
77
  def creatornames_roles_allowed
77
- %w(author performer adapter translator editor distributor)
78
+ %w(author performer adapter translator editor distributor authorizer)
78
79
  end
79
80
 
80
81
  def creatornames1(doc)
@@ -152,6 +153,15 @@ module Relaton
152
153
  x.nil? and return nil
153
154
  x.map { |c| extractname(c) }
154
155
  end
156
+
157
+ def authorizer(doc, host)
158
+ x = pick_contributor(doc, "authorizer") ||
159
+ pick_contributor(doc, "publisher")
160
+ host and x ||= pick_contributor(host, "authorizer") ||
161
+ pick_contributor(host, "publisher")
162
+ x.nil? and return nil
163
+ x.map { |c| extractname(c) }
164
+ end
155
165
  end
156
166
  end
157
167
  end
@@ -7,8 +7,7 @@ module Relaton
7
7
 
8
8
  # TODO : first is naive choice
9
9
  def title(doc)
10
- return nil if doc.nil? || doc.title.empty?
11
-
10
+ doc.nil? || doc.title.empty? and return nil
12
11
  t = doc.title.select { |x| x.title.language&.include? @lang }
13
12
  t.empty? and t = doc.title
14
13
  t1 = t.select { |x| x.type == "main" }
@@ -62,8 +61,7 @@ module Relaton
62
61
  end
63
62
 
64
63
  def series_title(series, _doc)
65
- return nil if series.nil?
66
-
64
+ series.nil? and return nil
67
65
  series.title.respond_to?(:titles) && !series.title.titles.empty? and
68
66
  return content(series.title.titles.first.title)
69
67
  series.title.respond_to?(:title) and
@@ -122,8 +120,7 @@ module Relaton
122
120
  u.language == @lang && !u.type&.casecmp("doi")&.zero?
123
121
  end
124
122
  uri ||= doc.link.detect { |u| !u.type&.casecmp("doi")&.zero? }
125
- return nil unless uri
126
-
123
+ uri or return nil
127
124
  uri.content.to_s.strip
128
125
  end
129
126
 
@@ -172,9 +169,8 @@ module Relaton
172
169
  end
173
170
 
174
171
  def draft(doc, host)
175
- dr = doc.status&.stage&.value || host&.status&.stage&.value
176
-
177
- { iteration: iter_ordinal(doc) || iter_ordinal(host), status: dr }
172
+ { iteration: iter_ordinal(doc) || iter_ordinal(host),
173
+ status: status(doc) || status(host) }
178
174
  end
179
175
 
180
176
  def iter_ordinal(doc)
@@ -184,7 +180,7 @@ module Relaton
184
180
  end
185
181
 
186
182
  def status(doc)
187
- doc.status&.stage&.value
183
+ doc&.status&.stage&.value
188
184
  end
189
185
 
190
186
  private
@@ -202,10 +198,8 @@ module Relaton
202
198
 
203
199
  def localized_string_or_text(str)
204
200
  case str
205
- when RelatonBib::LocalizedString
206
- content(str)
207
- when String
208
- str
201
+ when RelatonBib::LocalizedString then content(str)
202
+ when String then str
209
203
  end
210
204
  end
211
205
  end
@@ -1,5 +1,5 @@
1
1
  module Relaton
2
2
  module Render
3
- VERSION = "0.5.7".freeze
3
+ VERSION = "0.5.9".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-render
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.5.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-11 00:00:00.000000000 Z
11
+ date: 2022-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler