relaton-render 3.0.0.pre.alpha.35 → 3.0.0.pre.alpha.36

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: 81c57319ba531b5c63b0adcad897b4abbefac37099990a625993dab5357c7a32
4
- data.tar.gz: 1316576d47fdfccd9007c5ef98dfa3d40d0ca4ab5dca8a3de4cc822ebccdb657
3
+ metadata.gz: 8cc3d3010efcd83bdec9412ff02d171123404ca088993b6eed94b7480fe5e7a9
4
+ data.tar.gz: 4b88cbd036bdb0a4b4f35d3b5c290656225bb9360236219b0842269ad64cc327
5
5
  SHA512:
6
- metadata.gz: 36b05f7515bddf6f44a728174a57f365398c0f28aa55b2e3228ea651eadbf0d8c7a7c02ddd70c2b4375b53df83aa13bb896b6be27298e4d8e675a394aeca3d23
7
- data.tar.gz: a8d0e79f9349ccd80efb408c04789f791dea1b21e510ab3cfd2ce5cfd65d912ef1a5d6b42047d8ad60cec88c65c0a92e8a3c90981e5bb9739d622837ee02aa1f
6
+ metadata.gz: 5c397f214df631e40b4352209c4a45deabe77363eb7d1f8ede9f88e4e4245da3a21ae179f139b21a897fab353a5df369b91075314ba0a78955478467e573435e
7
+ data.tar.gz: 57d5c764a1307b5e620aa28ec875723d88d38b4f1d8e7acb01b9da7e2e4f6463f843ebcba4a30858f9f7bf68f291d02e9cba711eb664283d5ea61c0102a49bdc
@@ -292,8 +292,8 @@ is a rule to promote:
292
292
  |`ItuIdentifier` |**[impl]** promoted: `identifier: itu_identifier`
293
293
  |`NistIdentifier`, `NistCreator`, `NistDate`, `SerialDate`, `NistSeries`, `NistComponentPart`, `NistPublisher`, `Draft` |**[impl]** promoted: `nist_identifier`, `nist_creator`, `nist_date`, `nist_serial_date`, `nist_series`, `nist_component_part`, `nist_publisher`, `nist_draft`
294
294
  |`IeeeIdentifier`, `IeeeComponentPart`, `IeeeAccess`, `IeeeMedium` |**[impl]** promoted: `ieee_identifier`, `ieee_component_part`, `ieee_access`, `ieee_medium`
295
- |`BipmCreator`, `BipmComponentPart`, `BipmProduction`, `BipmExtent`, `BipmMedium`, `BipmEdition`, `BipmVolume` |the BIPM rule set
296
- |`IhoEdition`, `IhoCreator` |affiliation-composite creators
295
+ |`BipmCreator`, `BipmComponentPart`, `BipmProduction`, `BipmExtent`, `BipmMedium`, `BipmEdition`, `BipmVolume` |**[impl]** promoted: `bipm_creator`, `bipm_component_part`, `bipm_production`, `bipm_extent`, `bipm_medium`, `bipm_edition`, `bipm_volume` (slot `volsize`)
296
+ |`IhoEdition`, `IhoCreator` |**[impl]** promoted: `iho_edition`, `iho_creator` (the %w publisher list could never match the multiword organization name — now a string array)
297
297
  |`JisComponentPart`, `JisSeries`, `JisExtent` |the JIS host-citation rules
298
298
  |`BsiStatus` |status presentation
299
299
  |===
@@ -0,0 +1,183 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Relaton
4
+ module Render
5
+ module Iso690
6
+ module Rules
7
+ # The BIPM rule set, moved verbatim from the metanorma-bipm
8
+ # flavor's BipmElements: the affiliation-free organization
9
+ # creator, the bold-volume journal numeration, the
10
+ # no-place-with-publisher production, the separator-carrying
11
+ # edition and medium, and the component-part host order.
12
+ # Select from pack data:
13
+ # rules: { creator: bipm_creator, ... }
14
+ module Bipm
15
+ # The BIPM component-part order: the host editors before the
16
+ # host title, the host medium after it, and the production
17
+ # parenthesized with its own trailing period
18
+ class BipmComponentPart < Elements::ComponentPart
19
+ def render
20
+ h = host or return ""
21
+ out = +"#{lead}#{host_names(h)} (#{eds_label(h)})"
22
+ out += " #{host_title}" unless host_title_text.empty?
23
+ out += medium_text(h)
24
+ out += production_text(h)
25
+ out
26
+ end
27
+
28
+ private
29
+
30
+ def host_editors(h)
31
+ Array(h.contributor).select { |c| has_role?(c, "editor") }
32
+ end
33
+
34
+ def eds_label(h)
35
+ @i18n.label(host_editors(h).one? ? "ed" : "eds")
36
+ end
37
+
38
+ def host_names(h)
39
+ names = host_editors(h).map { |c|
40
+ person = c.person or next ""
41
+
42
+ [person_surname(person), person_given(person)].reject(&:empty?)
43
+ .join(" ")
44
+ }.reject(&:empty?)
45
+ join_names(names)
46
+ end
47
+
48
+ def medium_text(h)
49
+ BipmMedium.new(h, style: @style, i18n: @i18n).render.to_s
50
+ end
51
+
52
+ def production_text(h)
53
+ production = Elements::Production
54
+ .new(h, style: @style, i18n: @i18n).render.to_s
55
+ production.empty? ? "" : " (#{production})."
56
+ end
57
+ end
58
+
59
+ # The BIPM journal numeration: the volume bold and the issue
60
+ # in parens, pages unlabelled. Separate extent elements join
61
+ # with semicolons, localities within one element with spaces
62
+ class BipmExtent < Elements::Extent
63
+ def render
64
+ groups = extent_locality_groups.map { |g| group_text(g) }
65
+ .reject(&:empty?)
66
+ groups.join("; ")
67
+ end
68
+
69
+ private
70
+
71
+ def extent_locality_groups
72
+ Array(@model.extent).map do |e|
73
+ Array(e.locality) +
74
+ Array(e.locality_stack).flat_map { |s| Array(s.locality) }
75
+ end
76
+ end
77
+
78
+ def group_text(localities)
79
+ volume = plain_locality(localities, "volume")
80
+ volume = volume.empty? ? "" : "<strong>#{volume}</strong>"
81
+ issue = plain_locality(localities, "issue")
82
+ issue = issue.empty? ? "" : "(#{issue})"
83
+ [volume, issue, page_text(localities)].reject(&:empty?).join(" ")
84
+ end
85
+
86
+ def plain_locality(localities, type)
87
+ loc = localities.find { |l| l.type == type } or return ""
88
+ loc.reference_from.to_s
89
+ end
90
+
91
+ def page_text(localities)
92
+ loc = localities.find { |l| l.type == "page" } or return ""
93
+ from = loc.reference_from.to_s
94
+ to = loc.reference_to.to_s
95
+ text = to.empty? || to == from ? from :
96
+ "#{from}#{@i18n.label('date_range')}#{to}"
97
+ return text if item_kind == "serial_part"
98
+
99
+ "#{@i18n.label(to.empty? || to == from ? 'page' : 'pages')} #{text}"
100
+ end
101
+ end
102
+
103
+ # The BIPM production: the no-place placeholder stands only
104
+ # with a publisher ("(n.p.: Publisher)"); a nameless
105
+ # publisher drops the production entirely
106
+ class BipmProduction < Elements::Production
107
+ private
108
+
109
+ def no_place_production
110
+ return "" if publishers.empty?
111
+
112
+ super
113
+ end
114
+ end
115
+
116
+ # The serial volume, bold, from the size's volume value
117
+ class BipmVolume < Element
118
+ def present?
119
+ !render.empty?
120
+ end
121
+
122
+ def render
123
+ volume = Array(@model.size&.value).find do |v|
124
+ !v.is_a?(String) && !v.is_a?(Hash) && v.type == "volume"
125
+ end or return ""
126
+
127
+ "<strong>#{volume.content}</strong>"
128
+ end
129
+ end
130
+
131
+ # The BIPM medium, verbatim and bracketed with its leading
132
+ # separator (" [Online]", " [dataset]") — an absent medium
133
+ # attaches to nothing
134
+ class BipmMedium < Elements::Medium
135
+ private
136
+
137
+ def medium
138
+ m = @model.medium or return ""
139
+ text = m.carrier.to_s
140
+ text = m.genre.to_s if text.empty?
141
+ text = [m.form.to_s, m.size.to_s].reject(&:empty?)
142
+ .join(", ") if text.empty?
143
+ text.empty? ? "" : " [#{text}]"
144
+ end
145
+ end
146
+
147
+ # The BIPM edition carries its own leading separator (",
148
+ # First edition" for monographs, ". Version 2" online), so
149
+ # its absence drops the separator with it
150
+ class BipmEdition < Elements::Edition
151
+ def render
152
+ text = super.to_s
153
+ sep = item_kind == "monograph" ? ", " : ". "
154
+ text.empty? ? "" : "#{sep}#{text}"
155
+ end
156
+ end
157
+
158
+ # The BIPM organization creator: the name alone, no
159
+ # abbreviation suffix. Standards without personal creators
160
+ # cite their publisher's name; monographs cite nothing
161
+ class BipmCreator < Elements::Creator
162
+ private
163
+
164
+ def org_name(contributor)
165
+ Array(contributor.organization&.name).map { |n| localized(n) }
166
+ .join(", ")
167
+ end
168
+
169
+ def fallback_name
170
+ return "" if %w[monograph continuing component_part]
171
+ .include?(@style.kind_for(@model.type))
172
+
173
+ publishers = contributors("publisher").filter_map do |c|
174
+ localized(Array(c.organization&.name).first)
175
+ end
176
+ publishers.reject(&:empty?).first.to_s
177
+ end
178
+ end
179
+ end
180
+ end
181
+ end
182
+ end
183
+ end
@@ -106,8 +106,70 @@ module Relaton
106
106
  end
107
107
  end
108
108
 
109
- # The NIST rule set lives in its own autoloaded section
109
+ # The IHO creator cites the affiliation's organization name
110
+ # after the creator list ("D. Balenson, Internet Engineering
111
+ # Task Force")
112
+ class IhoCreator < Elements::Creator
113
+ def render
114
+ out = super.to_s
115
+ aff = affiliation_names
116
+ out.empty? || aff.empty? ? out : "#{out}, #{aff}"
117
+ end
118
+
119
+ private
120
+
121
+ def affiliation_names
122
+ creators.filter_map do |c|
123
+ person = c.person or next ""
124
+
125
+ Array(person.affiliation).filter_map do |a|
126
+ Array(a.organization&.name).map(&:content).first.to_s
127
+ end.reject(&:empty?).first.to_s
128
+ end.reject(&:empty?).uniq.join(", ")
129
+ end
130
+ end
131
+
132
+ # The IHO edition cites only for IHO-published documents, as
133
+ # the raw numeric edition carrying its own label ("edition
134
+ # 3.1.0"); worded editions ("Revision 1") cite as nothing
135
+ class IhoEdition < Elements::Edition
136
+ def render
137
+ return "" unless iho_publisher?
138
+
139
+ text = edition_text
140
+ text.match?(/\A\d/) ? " edition #{text}" : ""
141
+ end
142
+
143
+ private
144
+
145
+ def edition_text
146
+ raw = @model.edition
147
+ raw.respond_to?(:content) ? raw.content.to_s : raw.to_s
148
+ end
149
+
150
+ def iho_publisher?
151
+ Array(@model.contributor).any? do |c|
152
+ next false unless Array(c.role).any? do |r|
153
+ r.is_a?(String) ? r == "publisher" : r.type == "publisher"
154
+ end
155
+
156
+ org = c.organization or next false
157
+ names = Array(org.name).map(&:content) +
158
+ [org.abbreviation&.content.to_s]
159
+ # a string array: %w[] would split the organization's
160
+ # full name into words and never match it
161
+ names.any? do |n|
162
+ ["IHO", "International Hydrographic Organization"]
163
+ .include?(n)
164
+ end
165
+ end
166
+ end
167
+ end
168
+
169
+ # The NIST and BIPM rule sets live in their own autoloaded
170
+ # sections
110
171
  autoload :Nist, "relaton/render/iso690/rules/nist"
172
+ autoload :Bipm, "relaton/render/iso690/rules/bipm"
111
173
 
112
174
  REGISTRY = {
113
175
  "status_bare" => BareStatus,
@@ -124,6 +186,15 @@ module Relaton
124
186
  "nist_identifier" => Nist::NistIdentifier,
125
187
  "nist_publisher" => Nist::NistPublisher,
126
188
  "nist_draft" => Nist::NistDraft,
189
+ "iho_creator" => IhoCreator,
190
+ "iho_edition" => IhoEdition,
191
+ "bipm_creator" => Bipm::BipmCreator,
192
+ "bipm_component_part" => Bipm::BipmComponentPart,
193
+ "bipm_production" => Bipm::BipmProduction,
194
+ "bipm_extent" => Bipm::BipmExtent,
195
+ "bipm_medium" => Bipm::BipmMedium,
196
+ "bipm_edition" => Bipm::BipmEdition,
197
+ "bipm_volume" => Bipm::BipmVolume,
127
198
  }.freeze
128
199
 
129
200
  class << self
@@ -1,5 +1,5 @@
1
1
  module Relaton
2
2
  module Render
3
- VERSION = "3.0.0.pre.alpha.35".freeze
3
+ VERSION = "3.0.0.pre.alpha.36".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-render
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.pre.alpha.35
4
+ version: 3.0.0.pre.alpha.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -148,6 +148,7 @@ files:
148
148
  - lib/relaton/render/iso690/kinds.rb
149
149
  - lib/relaton/render/iso690/renderer.rb
150
150
  - lib/relaton/render/iso690/rules.rb
151
+ - lib/relaton/render/iso690/rules/bipm.rb
151
152
  - lib/relaton/render/iso690/rules/nist.rb
152
153
  - lib/relaton/render/iso690/style.rb
153
154
  - lib/relaton/render/iso690/style/locale.rb