relaton-bib 1.6.pre1 → 1.7.1

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: c9741b425d8415304b51078b9a7c649560abccdecbec0ead58986994209b4baf
4
- data.tar.gz: 9ec3425ae7f42bc668be546058c6d7b7ff5a4be4bd345b9f0f74c4ca26be2db5
3
+ metadata.gz: e9ebdb538f6fb256157a23a01994bb4654df470e7d9abe245d8de7ff88d5fecf
4
+ data.tar.gz: 56e5146c1d0a6f0c02c12d17d30a3041bb3eabff1b54e0c6f0478f7c7a4743ac
5
5
  SHA512:
6
- metadata.gz: 66bd1804ab23745be33b2990dec11c84e7a9e1b70e192604e131d298cf88893bff94f20648085099c7505d5b201d54886f6e96eeb9d5ef4694495794e7203242
7
- data.tar.gz: c0d5e9ce4b7dba3f22f1834017f58afbf2a826be3eefbe67e6bfd6ca0fb9fe1310dc7dc55f71b783137d5f3df2011c4f54cb717bb07aa798cc28c535b94ccc34
6
+ metadata.gz: 692cce83ac3ce023196a5dd6a06ed30a07cfb442407c02249e948866932db7d0c81a49a7aa8b34afa05c995e9cbcbccdbb7141bd10e699657b545ec3d906918a
7
+ data.tar.gz: c823d2926c8c50810c2989de01f06afbd47e104ff458269d8c17db79e2281550d499d5f267fa1324924005a15de86111b52c2b3cc62142140d09fb9526b14025
@@ -24,6 +24,14 @@
24
24
  <start>
25
25
  <ref name="standard-document"/>
26
26
  </start>
27
+ <define name="doctype">
28
+ <element name="doctype">
29
+ <optional>
30
+ <attribute name="abbreviation"/>
31
+ </optional>
32
+ <ref name="DocumentType"/>
33
+ </element>
34
+ </define>
27
35
  <define name="hyperlink">
28
36
  <element name="link">
29
37
  <attribute name="target">
@@ -141,6 +149,11 @@
141
149
  <data type="boolean"/>
142
150
  </attribute>
143
151
  </optional>
152
+ <optional>
153
+ <attribute name="key">
154
+ <data type="boolean"/>
155
+ </attribute>
156
+ </optional>
144
157
  <oneOrMore>
145
158
  <ref name="dt"/>
146
159
  <ref name="dd"/>
@@ -1164,49 +1177,7 @@
1164
1177
  </define>
1165
1178
  <define name="annex">
1166
1179
  <element name="annex">
1167
- <optional>
1168
- <attribute name="id">
1169
- <data type="ID"/>
1170
- </attribute>
1171
- </optional>
1172
- <optional>
1173
- <attribute name="language"/>
1174
- </optional>
1175
- <optional>
1176
- <attribute name="script"/>
1177
- </optional>
1178
- <optional>
1179
- <attribute name="inline-header">
1180
- <data type="boolean"/>
1181
- </attribute>
1182
- </optional>
1183
- <attribute name="obligation">
1184
- <choice>
1185
- <value>normative</value>
1186
- <value>informative</value>
1187
- </choice>
1188
- </attribute>
1189
- <optional>
1190
- <ref name="section-title"/>
1191
- </optional>
1192
- <group>
1193
- <group>
1194
- <zeroOrMore>
1195
- <ref name="BasicBlock"/>
1196
- </zeroOrMore>
1197
- <zeroOrMore>
1198
- <ref name="note"/>
1199
- </zeroOrMore>
1200
- </group>
1201
- <zeroOrMore>
1202
- <choice>
1203
- <ref name="annex-subsection"/>
1204
- <ref name="terms"/>
1205
- <ref name="definitions"/>
1206
- <ref name="references"/>
1207
- </choice>
1208
- </zeroOrMore>
1209
- </group>
1180
+ <ref name="Annex-Section"/>
1210
1181
  </element>
1211
1182
  </define>
1212
1183
  <define name="terms">
@@ -15,7 +15,7 @@ module RelatonBib
15
15
  # @param date [String, Integer, Date]
16
16
  # @param str [Boolean]
17
17
  # @return [Date, nil]
18
- def parse_date(date, str = true) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
18
+ def parse_date(date, str = true) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity,Metrics/AbcSize
19
19
  return date if date.is_a?(Date)
20
20
 
21
21
  case date.to_s
@@ -62,9 +62,10 @@ module RelatonBib
62
62
  # @return [String]
63
63
  def to_asciibib(prefix = "", count = 1)
64
64
  pref = prefix.empty? ? prefix : prefix + "."
65
- out = count > 1 ? "#{pref}biblionote::\n" : ""
66
- out + "#{pref}biblionote.type:: #{type}\n" if type
67
- out += super "#{pref}biblionote"
65
+ has_attrs = !(type.nil? || type.empty?)
66
+ out = count > 1 && has_attrs ? "#{pref}biblionote::\n" : ""
67
+ out += "#{pref}biblionote.type:: #{type}\n" if type
68
+ out += super "#{pref}biblionote", 1, has_attrs
68
69
  out
69
70
  end
70
71
  end
@@ -31,12 +31,12 @@ module RelatonBib
31
31
  # @return [String, Date, nil]
32
32
  def from(part = nil)
33
33
  d = instance_variable_get "@#{__callee__}".to_sym
34
- return d unless part
34
+ return d unless part && d
35
35
 
36
36
  date = parse_date(d)
37
37
  return date if part == :date
38
38
 
39
- date.send part
39
+ date.is_a?(Date) ? date.send(part) : date
40
40
  end
41
41
 
42
42
  alias_method :to, :from
@@ -87,20 +87,23 @@ module RelatonBib
87
87
  # @param format [Symbol, nil] :full (yyyy-mm-dd), :short (yyyy-mm) or nil
88
88
  # @return [String]
89
89
  def date_format(date, format = nil)
90
- case format
91
- when :short then parse_date(date).strftime "%Y-%m"
92
- when :full then parse_date(date).strftime "%Y-%m-%d"
93
- else date
94
- end
90
+ tmplt = case format
91
+ when :short then "%Y-%m"
92
+ when :full then "%Y-%m-%d"
93
+ else return date
94
+ end
95
+ d = parse_date(date)
96
+ d.is_a?(Date) ? d.strftime(tmplt) : d
95
97
  end
96
98
 
97
99
  # @param date [String]
98
100
  # @return [Date]
99
101
  def parse_date(date)
100
102
  case date
101
- when /\d{4}-\d{2}-\d{2}/ then Date.parse(date) # 2012-02-11
102
- when /\d{4}-\d{2}/ then Date.strptime(date, "%Y-%m") # 2012-02
103
- when /\d{4}/ then Date.strptime(date, "%Y") # 2012
103
+ when /^\d{4}-\d{2}-\d{2}/ then Date.parse(date) # 2012-02-11
104
+ when /^\d{4}-\d{2}/ then Date.strptime(date, "%Y-%m") # 2012-02
105
+ when /^\d{4}/ then Date.strptime(date, "%Y") # 2012
106
+ else date
104
107
  end
105
108
  end
106
109
  end
@@ -399,7 +399,7 @@ module RelatonBib
399
399
  # @param type [Symbol] type of url, can be :src/:obp/:rss
400
400
  # @return [String]
401
401
  def url(type = :src)
402
- @link.detect { |s| s.type == type.to_s }.content.to_s
402
+ @link.detect { |s| s.type == type.to_s }&.content&.to_s
403
403
  end
404
404
 
405
405
  def abstract=(value)
@@ -81,8 +81,11 @@ module RelatonBib
81
81
  attr_reader :entity
82
82
 
83
83
  # @param entity [RelatonBib::Person, RelatonBib::Organization]
84
- # @param role [Array<String>]
85
- def initialize(entity:, role: [{ type: "publisher" }])
84
+ # @param role [Array<Hash>]
85
+ def initialize(entity:, role: [])
86
+ if role.empty?
87
+ role << { type: entity.is_a?(Person) ? "author" : "publisher" }
88
+ end
86
89
  @entity = entity
87
90
  @role = role.map { |r| ContributorRole.new(**r) }
88
91
  end
@@ -44,7 +44,8 @@ module RelatonBib
44
44
  # @param prefix [String]
45
45
  # @param count [Integer] number of elements
46
46
  # @return [String]
47
- def to_asciibib(prefix = "", count = 1)
47
+ def to_asciibib(prefix = "", count = 1, has_attrs = false)
48
+ has_attrs ||= !(format.nil? || format.empty?)
48
49
  pref = prefix.empty? ? prefix : prefix + "."
49
50
  # out = count > 1 ? "#{prefix}::\n" : ""
50
51
  out = super
@@ -120,12 +120,12 @@ module RelatonBib
120
120
  end
121
121
  end
122
122
 
123
- def docid_hash_to_bib(ret)
123
+ def docid_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize
124
124
  return unless ret[:docid]
125
125
 
126
126
  ret[:docid] = array(ret[:docid])
127
127
  ret[:docid]&.each_with_index do |id, i|
128
- type = id[:type] || id[:id].match(/^\w+\s/)&.to_s
128
+ type = id[:type] || id[:id].match(/^\w+(?=\s)/)&.to_s
129
129
  ret[:docid][i] = DocumentIdentifier.new(id: id[:id], type: type,
130
130
  scope: id[:scope])
131
131
  end
@@ -219,7 +219,7 @@ module RelatonBib
219
219
  )
220
220
  end
221
221
 
222
- def fullname_hash_to_bib(person) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
222
+ def fullname_hash_to_bib(person) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
223
223
  n = person[:name]
224
224
  FullName.new(
225
225
  forename: array(n[:forename])&.map { |f| localname(f, person) },
@@ -77,9 +77,13 @@ module RelatonBib
77
77
  # @param prefix [String]
78
78
  # @param count [Integer] number of elements
79
79
  # @return [String]
80
- def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
80
+ def to_asciibib(prefix = "", count = 1, has_attrs = false) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
81
81
  pref = prefix.empty? ? prefix : prefix + "."
82
82
  if content.is_a? String
83
+ unless language&.any? || script&.any? || has_attrs
84
+ return "#{prefix}:: #{content}\n"
85
+ end
86
+
83
87
  out = count > 1 ? "#{prefix}::\n" : ""
84
88
  out += "#{pref}content:: #{content}\n"
85
89
  language&.each { |l| out += "#{pref}language:: #{l}\n" }
@@ -162,7 +162,7 @@ module RelatonBib
162
162
  pref = prefix.empty? ? prefix : prefix + "."
163
163
  out = count > 1 ? "#{pref}title::\n" : ""
164
164
  out += "#{pref}title.type:: #{type}\n" if type
165
- out += title.to_asciibib "#{pref}title"
165
+ out += title.to_asciibib "#{pref}title", 1, !(type.nil? || type.empty?)
166
166
  out
167
167
  end
168
168
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.6.pre1".freeze
2
+ VERSION = "1.7.1".freeze
3
3
  end
@@ -177,16 +177,22 @@ module RelatonBib
177
177
  def ttitle(title)
178
178
  return unless title
179
179
 
180
- variants = title.xpath("variant").map do |v|
181
- LocalizedString.new v.text, v[:language], v[:script]
182
- end
183
- content = variants.any? ? variants : title.text
180
+ content = variants(title)
181
+ content = title.text unless content.any?
184
182
  TypedTitleString.new(
185
183
  type: title[:type], content: content, language: title[:language],
186
184
  script: title[:script], format: title[:format]
187
185
  )
188
186
  end
189
187
 
188
+ # @param title [Nokogiri::XML::Element]
189
+ # @return [Array<RelatonBib::LocalizedString>]
190
+ def variants(elm)
191
+ elm.xpath("variant").map do |v|
192
+ LocalizedString.new v.text, v[:language], v[:script]
193
+ end
194
+ end
195
+
190
196
  def fetch_status(item)
191
197
  status = item.at("./status")
192
198
  return unless status
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-bib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.pre1
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-11 00:00:00.000000000 Z
11
+ date: 2020-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -259,9 +259,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
259
259
  version: 2.4.0
260
260
  required_rubygems_version: !ruby/object:Gem::Requirement
261
261
  requirements:
262
- - - ">"
262
+ - - ">="
263
263
  - !ruby/object:Gem::Version
264
- version: 1.3.1
264
+ version: '0'
265
265
  requirements: []
266
266
  rubygems_version: 3.0.6
267
267
  signing_key: