relaton-render 0.5.8 → 0.5.10

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: 57ebdb614711c3fdca1166a3017396ce04245c92cfb793940efdc9da6d3d4c6d
4
- data.tar.gz: e548c4fb11f390c585eaa95c4d7ccc77111d9166ecdf4fad795fa2c4181990e0
3
+ metadata.gz: be542bce28bee8b30b8a719d8e6e822fb998c7d042c2c7b546309733c3ca1d66
4
+ data.tar.gz: 5be41eba5e9771af4d39bcf7e2df8d4344db4ad9275d2fbf97fcb9c3f7eef362
5
5
  SHA512:
6
- metadata.gz: f8e53bff23c39d72ecb3d9167f92c9d6570d09148fdb5907fccbc018e974302e591101fe2e491014a6a4fbafff00960ae84de3a477ad6568416c02ab2274d15d
7
- data.tar.gz: 6c699eaec0669e07ebb7ac9e1e43a2c31e7b303158d900117abe580fee599a8fde92409c861eca3e4c8b85c750bbab1141087d753dc9ac02be6fa7704871f58a
6
+ metadata.gz: 54acff0f3354e44e6af2fe54fc20dd1f1f814b4d632604e820b6ab72a04275dc0b46dcd7981dd7a12f17ddea05506ed73b7c6401b31fe35097b90d5352ea3b5b
7
+ data.tar.gz: 4a584b500e0e6438fdc69340386c641e6f79780ca8cbe0d01811fddcb0d5baafa99e5679a447efad08e5e6e15d4de2ba5dd56fc7e4832ee914ec6412009d1dd9
data/README.adoc CHANGED
@@ -155,16 +155,17 @@ 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
- | date | ./date[@type = 'issued'] \| ./date[@type = 'circulated'] \| ./date | | Y |
168
+ | date | ./date[@type = 'issued'] \| ./date[@type = 'circulated'] \| ./date | | Y | Always truncated to just year
168
169
  | date_updated | ./date[@type = 'updated'] | | Y |
169
170
  | date_accessed | ./date[@type = 'accessed'] | | Y |
170
171
  | series | ./series[@type = 'main' or not(@type) or true] | | Y | <<seriestemplate,`seriestemplate`>> applies to series
@@ -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
 
@@ -159,12 +157,12 @@ module Relaton
159
157
  end
160
158
 
161
159
  def range(hash)
162
- if hash[:on] then hash[:on]
163
- elsif hash.has_key?(:from) && hash[:from].nil? then nil
164
- elsif hash[:from]
165
- hash[:to] ? "#{hash[:from]}&#x2013;#{hash[:to]}" : hash[:from]
166
- else hash
167
- end
160
+ hash[:on] and return hash[:on]
161
+ hash.has_key?(:from) && hash[:from].nil? and return nil
162
+ !hash[:from] and return hash
163
+ hash[:to] && hash[:to] != hash[:from] and
164
+ return "#{hash[:from]}&#x2013;#{hash[:to]}"
165
+ hash[:from]
168
166
  end
169
167
 
170
168
  def sizeformat(size, hash)
@@ -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"
@@ -208,15 +199,12 @@ module Relaton
208
199
  end
209
200
 
210
201
  def date_range(hash)
211
- if hash[:from]
212
- "#{hash[:from]}&#x2013;#{hash[:to]}"
213
- else range(hash)
214
- end
202
+ hash[:from] && !hash[:to] and return "#{hash[:from]}&#x2013;"
203
+ range(hash)
215
204
  end
216
205
 
217
206
  def dateformat(date, _hash)
218
- return nil if date.nil?
219
-
207
+ date.nil? and return nil
220
208
  %i(from to on).each do |k|
221
209
  date[k] = ::Relaton::Render::Date.new(date[k], renderer: @r).render
222
210
  end
@@ -224,20 +212,16 @@ module Relaton
224
212
  end
225
213
 
226
214
  def uriformat(uri)
227
- return nil if uri.nil? || uri.empty?
228
-
215
+ uri.nil? || uri.empty? and return nil
229
216
  "<link target='#{uri}'>#{uri}</link>"
230
217
  end
231
218
 
232
219
  private
233
220
 
234
221
  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"
222
+ if @r.lang != "zh" then @r.lang.to_sym
223
+ elsif @r.script == "Hant" then :"zh-tw"
224
+ else :"zh-cn"
241
225
  end
242
226
  end
243
227
  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) }
@@ -75,7 +75,7 @@ module Relaton
75
75
  end
76
76
 
77
77
  def creatornames_roles_allowed
78
- %w(author performer adapter translator editor distributor)
78
+ %w(author performer adapter translator editor distributor authorizer)
79
79
  end
80
80
 
81
81
  def creatornames1(doc)
@@ -112,10 +112,13 @@ module Relaton
112
112
  date.first
113
113
  end
114
114
 
115
+ # year-only
115
116
  def date(doc, host)
116
117
  ret = date1(doc.date)
117
118
  host and ret ||= date1(host.date)
118
- datepick(ret)
119
+ datepick(ret)&.transform_values do |v|
120
+ v&.sub(/-.*$/, "")
121
+ end
119
122
  end
120
123
 
121
124
  def date_updated(doc, host)
@@ -153,6 +156,15 @@ module Relaton
153
156
  x.nil? and return nil
154
157
  x.map { |c| extractname(c) }
155
158
  end
159
+
160
+ def authorizer(doc, host)
161
+ x = pick_contributor(doc, "authorizer") ||
162
+ pick_contributor(doc, "publisher")
163
+ host and x ||= pick_contributor(host, "authorizer") ||
164
+ pick_contributor(host, "publisher")
165
+ x.nil? and return nil
166
+ x.map { |c| extractname(c) }
167
+ end
156
168
  end
157
169
  end
158
170
  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
@@ -104,8 +102,9 @@ module Relaton
104
102
 
105
103
  def other_identifier(doc)
106
104
  doc.docidentifier.each_with_object([]) do |id, ret|
107
- other_identifier_include.include? id.type or next
108
- ret << @i18n.l10n("#{id.type}: #{id.id}")
105
+ type = id.type&.sub(/^(ISBN|ISSN)\..*$/, "\\1")
106
+ other_identifier_include.include? type or next
107
+ ret << @i18n.l10n("#{type}: #{id.id}")
109
108
  end
110
109
  end
111
110
 
@@ -122,8 +121,7 @@ module Relaton
122
121
  u.language == @lang && !u.type&.casecmp("doi")&.zero?
123
122
  end
124
123
  uri ||= doc.link.detect { |u| !u.type&.casecmp("doi")&.zero? }
125
- return nil unless uri
126
-
124
+ uri or return nil
127
125
  uri.content.to_s.strip
128
126
  end
129
127
 
@@ -172,9 +170,8 @@ module Relaton
172
170
  end
173
171
 
174
172
  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 }
173
+ { iteration: iter_ordinal(doc) || iter_ordinal(host),
174
+ status: status(doc) || status(host) }
178
175
  end
179
176
 
180
177
  def iter_ordinal(doc)
@@ -184,7 +181,7 @@ module Relaton
184
181
  end
185
182
 
186
183
  def status(doc)
187
- doc.status&.stage&.value
184
+ doc&.status&.stage&.value
188
185
  end
189
186
 
190
187
  private
@@ -202,10 +199,8 @@ module Relaton
202
199
 
203
200
  def localized_string_or_text(str)
204
201
  case str
205
- when RelatonBib::LocalizedString
206
- content(str)
207
- when String
208
- str
202
+ when RelatonBib::LocalizedString then content(str)
203
+ when String then str
209
204
  end
210
205
  end
211
206
  end
@@ -1,5 +1,5 @@
1
1
  module Relaton
2
2
  module Render
3
- VERSION = "0.5.8".freeze
3
+ VERSION = "0.5.10".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.8
4
+ version: 0.5.10
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-19 00:00:00.000000000 Z
11
+ date: 2023-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler