relaton-bib 1.3.1 → 1.5.0

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.
@@ -25,7 +25,7 @@ module RelatonBib
25
25
  # @return [Hash]
26
26
  def to_hash
27
27
  if uri || region
28
- hash = { name: name }
28
+ hash = { "name" => name }
29
29
  hash["uri"] = uri if uri
30
30
  hash["region"] = region if region
31
31
  hash
@@ -1,4 +1,70 @@
1
1
  module RelatonBib
2
+ class TypedTitleStringCollection
3
+ extend Forwardable
4
+
5
+ def_delegators :@array, :[], :first, :last, :empty?, :any?, :size,
6
+ :each, :detect, :map, :length
7
+
8
+ # @param title [Array<RelatonBib::TypedTitleString, Hash>]
9
+ def initialize(title = [])
10
+ @array = (title || []).map do |t|
11
+ t.is_a?(Hash) ? TypedTitleString.new(t) : t
12
+ end
13
+ end
14
+
15
+ # @param lang [String, nil] language code Iso639
16
+ # @return [RelatonIsoBib::TypedTitleStringCollection]
17
+ def lang(lang = nil)
18
+ if lang
19
+ TypedTitleStringCollection.new select_lang(lang)
20
+ else self
21
+ end
22
+ end
23
+
24
+ def delete_title_part!
25
+ titles.delete_if { |t| t.type == "title-part" }
26
+ end
27
+
28
+ # @return [RelatonBib::TypedTitleStringCollection]
29
+ def select
30
+ TypedTitleStringCollection.new(titles.select { |t| yield t })
31
+ end
32
+
33
+ # @param title [RelatonBib::TypedTitleString]
34
+ # @return [self]
35
+ def <<(title)
36
+ titles << title
37
+ self
38
+ end
39
+
40
+ # @param tcoll [RelatonBib::TypedTitleStringCollection]
41
+ # @return [RelatonBib::TypedTitleStringCollection]
42
+ def +(tcoll)
43
+ TypedTitleStringCollection.new titles + tcoll.titles
44
+ end
45
+
46
+ def titles
47
+ @array
48
+ end
49
+
50
+ # @param opts [Hash]
51
+ # @option opts [Nokogiri::XML::Builder] XML builder
52
+ # @option opts [String, Symbol] :lang language
53
+ def to_xml(**opts)
54
+ tl = select_lang(opts[:lang])
55
+ tl = titles unless tl.any?
56
+ tl.each { |t| opts[:builder].title { t.to_xml opts[:builder] } }
57
+ end
58
+
59
+ private
60
+
61
+ # @param lang [String]
62
+ # @return [Array<RelatonBib::TypedTitleString]
63
+ def select_lang(lang)
64
+ titles.select { |t| t.title.language&.include? lang }
65
+ end
66
+ end
67
+
2
68
  class TypedTitleString
3
69
  # @return [String]
4
70
  attr_reader :type
@@ -38,6 +104,7 @@ module RelatonBib
38
104
  end.compact
39
105
  tts << new(type: "main", content: ttls.compact.join(" - "),
40
106
  language: lang, script: script)
107
+ TypedTitleStringCollection.new tts
41
108
  end
42
109
 
43
110
  # @param title [String]
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.3.1".freeze
2
+ VERSION = "1.5.0".freeze
3
3
  end
@@ -20,7 +20,7 @@ module RelatonBib
20
20
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
21
21
 
22
22
  # @return [Hash]
23
- def item_data(bibitem) # rubocop:disable Metrics/CyclomaticComplexity
23
+ def item_data(bibitem) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
24
24
  ext = bibitem.at "//ext"
25
25
  {
26
26
  id: bibitem[:id]&.empty? ? nil : bibitem[:id],
@@ -75,7 +75,7 @@ module RelatonBib
75
75
  end
76
76
 
77
77
  def fetch_note(item)
78
- item.xpath("./note").map do |n|
78
+ bnotes = item.xpath("./note").map do |n|
79
79
  BiblioNote.new(
80
80
  content: n.text,
81
81
  type: n[:type],
@@ -84,6 +84,7 @@ module RelatonBib
84
84
  script: n[:script]
85
85
  )
86
86
  end
87
+ BiblioNoteCollection.new bnotes
87
88
  end
88
89
 
89
90
  def fetch_language(item)
@@ -98,7 +99,7 @@ module RelatonBib
98
99
  end
99
100
  end
100
101
 
101
- def fetch_series(item) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
102
+ def fetch_series(item) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize,Metrics/MethodLength,Metrics/PerceivedComplexity
102
103
  item.xpath("./series").reduce([]) do |mem, sr|
103
104
  abbr = sr.at "abbreviation"
104
105
  abbreviation = abbr &&
@@ -164,10 +165,15 @@ module RelatonBib
164
165
  end
165
166
  end
166
167
 
168
+ # @param item [Nokogiri::XML::Element]
169
+ # @return [RelatonBib::TypedTitleStringCollection]
167
170
  def fetch_titles(item)
168
- item.xpath("./title").map { |t| ttitle t }
171
+ ttl = item.xpath("./title").map { |t| ttitle t }
172
+ TypedTitleStringCollection.new ttl
169
173
  end
170
174
 
175
+ # @param title [Nokogiri::XML::Element]
176
+ # @return [RelatonBib::TypedTitleString]
171
177
  def ttitle(title)
172
178
  return unless title
173
179
 
@@ -202,7 +208,9 @@ module RelatonBib
202
208
  abbreviation: elm[:abbreviation])
203
209
  end
204
210
 
205
- def fetch_dates(item) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
211
+ # @param node [Nokogiri::XML::Elemen]
212
+ # @return [Array<RelatonBib::BibliographicDate>]
213
+ def fetch_dates(item) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
206
214
  item.xpath("./date").reduce([]) do |a, d|
207
215
  type = d[:type].to_s.empty? ? "published" : d[:type]
208
216
  if (on = d.at("on"))
@@ -222,14 +230,15 @@ module RelatonBib
222
230
  identifier = org.xpath("./identifier").map do |i|
223
231
  OrgIdentifier.new(i[:type], i.text)
224
232
  end
233
+ subdiv = org.xpath("subdivision").map &:text
225
234
  Organization.new(name: names,
226
235
  abbreviation: org.at("abbreviation")&.text,
227
- subdivision: org.at("subdivision")&.text,
236
+ subdivision: subdiv,
228
237
  url: org.at("uri")&.text,
229
238
  identifier: identifier)
230
239
  end
231
240
 
232
- def get_person(person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
241
+ def get_person(person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
233
242
  affiliations = person.xpath("./affiliation").map do |a|
234
243
  org = a.at "./organization"
235
244
  desc = a.xpath("./description").map do |e|
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.3.1
4
+ version: 1.5.0
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-08-27 00:00:00.000000000 Z
11
+ date: 2020-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug