relaton-bib 1.11.7 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,11 +6,11 @@ module RelatonBib
6
6
  # @param args [Hash]
7
7
  # @param neated [TrueClas, FalseClass] default false
8
8
  # @return [Hash]
9
- def hash_to_bib(args, nested = false)
9
+ def hash_to_bib(args)
10
10
  return nil unless args.is_a?(Hash)
11
11
 
12
12
  ret = Marshal.load(Marshal.dump(symbolize(args))) # deep copy
13
- timestamp_hash(ret) unless nested
13
+ # timestamp_hash(ret) unless nested
14
14
  title_hash_to_bib(ret)
15
15
  link_hash_to_bib(ret)
16
16
  language_hash_to_bib(ret)
@@ -42,9 +42,9 @@ module RelatonBib
42
42
  end
43
43
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
44
44
 
45
- def timestamp_hash(ret)
46
- ret[:fetched] ||= Date.today.to_s
47
- end
45
+ # def timestamp_hash(ret)
46
+ # ret[:fetched] ||= Date.today.to_s
47
+ # end
48
48
 
49
49
  def extent_hash_to_bib(ret)
50
50
  return unless ret[:extent]
@@ -145,20 +145,17 @@ module RelatonBib
145
145
 
146
146
  ret[:docid] = array(ret[:docid])
147
147
  ret[:docid]&.each_with_index do |id, i|
148
- type = id[:type] || id[:id].match(/^\w+(?=\s)/)&.to_s
149
- ret[:docid][i] = DocumentIdentifier.new(
150
- id: id[:id], type: type, scope: id[:scope], primary: id[:primary],
151
- )
148
+ id[:type] ||= id[:id].match(/^\w+(?=\s)/)&.to_s
149
+ ret[:docid][i] = DocumentIdentifier.new(**id)
152
150
  end
153
151
  end
154
152
 
155
153
  def version_hash_to_bib(ret)
156
154
  return unless ret[:version]
157
155
 
158
- ret[:version][:draft] = array(ret[:version][:draft])
159
- ret[:version] && ret[:version] = BibliographicItem::Version.new(
160
- ret[:version][:revision_date], ret[:version][:draft]
161
- )
156
+ ret[:version] = array(ret[:version]).map do |v|
157
+ BibliographicItem::Version.new(v[:revision_date], v[:draft])
158
+ end
162
159
  end
163
160
 
164
161
  def biblionote_hash_to_bib(ret) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
@@ -219,7 +216,7 @@ module RelatonBib
219
216
  end
220
217
  end
221
218
 
222
- def org_hash_to_bib(org)
219
+ def org_hash_to_bib(org) # rubocop:disable Metrics/AbcSize
223
220
  return nil if org.nil?
224
221
 
225
222
  org[:identifier] = array(org[:identifier])&.map do |a|
@@ -321,7 +318,7 @@ module RelatonBib
321
318
  # @param rel [Hash] relation
322
319
  def relation_bibitem_hash_to_bib(rel)
323
320
  if rel[:bibitem]
324
- rel[:bibitem] = bib_item hash_to_bib(rel[:bibitem], true)
321
+ rel[:bibitem] = bib_item hash_to_bib(rel[:bibitem])
325
322
  else
326
323
  warn "[relaton-bib] bibitem missing: #{rel}"
327
324
  rel[:bibitem] = nil
@@ -344,7 +341,8 @@ module RelatonBib
344
341
 
345
342
  def locality_locality_stack(lls)
346
343
  if lls[:locality_stack]
347
- array(lls[:locality_stack]).map do |l|
344
+ array(lls[:locality_stack]).map do |lc|
345
+ l = lc[:locality] || lc
348
346
  Locality.new(l[:type], l[:reference_from], l[:reference_to])
349
347
  end
350
348
  else
@@ -13,7 +13,7 @@ module RelatonBib
13
13
  # @return [RelatonBib::FormattedRef, nil]
14
14
  attr_reader :formattedref
15
15
 
16
- # @return [RelatonBib::TypedTitleString, nil] title
16
+ # @return [RelatonBib::TypedTitleString] title
17
17
  attr_reader :title
18
18
 
19
19
  # @return [String, nil]
@@ -26,8 +26,7 @@ module RelatonBib
26
26
 
27
27
  # @param type [String, nil]
28
28
  # @param formattedref [RelatonBib::FormattedRef, nil]
29
- # @param title [RelatonBib::TypedTitleString, nil] title or
30
- # formattedref argument should be passed
29
+ # @param title [RelatonBib::TypedTitleString] title
31
30
  # @param place [String, nil]
32
31
  # @param orgaization [String, nil]
33
32
  # @param abbreviation [RelatonBib::LocalizedString, nil]
@@ -37,9 +36,8 @@ module RelatonBib
37
36
  # @param partnumber [String, nil]
38
37
  # @param run [String, nil]
39
38
  def initialize(**args)
40
- unless args[:title].is_a?(RelatonBib::TypedTitleString) ||
41
- args[:formattedref]
42
- raise ArgumentError, "argument `title` or `formattedref` should present"
39
+ unless args[:title].is_a?(RelatonBib::TypedTitleString)
40
+ raise ArgumentError, "argument `title` should present"
43
41
  end
44
42
 
45
43
  # if args[:type] && !TYPES.include?(args[:type])
@@ -65,19 +63,16 @@ module RelatonBib
65
63
  # @param builder [Nokogiri::XML::Builder]
66
64
  def to_xml(builder) # rubocop:disable Metrics/MethodLength
67
65
  xml = builder.series do
68
- if formattedref
69
- formattedref.to_xml builder
70
- else
71
- builder.title { title.to_xml builder }
72
- builder.place place if place
73
- builder.organization organization if organization
74
- builder.abbreviation { abbreviation.to_xml builder } if abbreviation
75
- builder.from from if from
76
- builder.to to if to
77
- builder.number number if number
78
- builder.partnumber partnumber if partnumber
79
- builder.run run if run
80
- end
66
+ formattedref&.to_xml builder
67
+ builder.title { title.to_xml builder }
68
+ builder.place place if place
69
+ builder.organization organization if organization
70
+ builder.abbreviation { abbreviation.to_xml builder } if abbreviation
71
+ builder.from from if from
72
+ builder.to to if to
73
+ builder.number number if number
74
+ builder.partnumber partnumber if partnumber
75
+ builder.run run if run
81
76
  end
82
77
  xml[:type] = type if type
83
78
  end
@@ -89,7 +84,7 @@ module RelatonBib
89
84
  hash = {}
90
85
  hash["type"] = type if type
91
86
  hash["formattedref"] = formattedref.to_hash if formattedref
92
- hash["title"] = title.to_hash if title
87
+ hash["title"] = title.to_hash
93
88
  hash["place"] = place if place
94
89
  hash["organization"] = organization if organization
95
90
  hash["abbreviation"] = abbreviation.to_hash if abbreviation
@@ -109,7 +104,7 @@ module RelatonBib
109
104
  out = count > 1 ? "#{pref}::\n" : ""
110
105
  out += "#{pref}.type:: #{type}\n" if type
111
106
  out += formattedref.to_asciibib pref if formattedref
112
- out += title.to_asciibib pref if title
107
+ out += title.to_asciibib pref
113
108
  out += "#{pref}.place:: #{place}\n" if place
114
109
  out += "#{pref}.organization:: #{organization}\n" if organization
115
110
  out += abbreviation.to_asciibib "#{pref}.abbreviation" if abbreviation
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.11.7".freeze
2
+ VERSION = "1.12.0".freeze
3
3
  end
@@ -33,7 +33,7 @@ module RelatonBib
33
33
  docnumber: bibitem.at("./docnumber")&.text,
34
34
  date: fetch_dates(bibitem),
35
35
  contributor: fetch_contributors(bibitem),
36
- edition: bibitem.at("./edition")&.text,
36
+ edition: fetch_edition(bibitem),
37
37
  version: fetch_version(bibitem),
38
38
  biblionote: fetch_note(bibitem),
39
39
  language: fetch_language(bibitem),
@@ -62,12 +62,18 @@ module RelatonBib
62
62
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
63
63
 
64
64
  def fetch_version(item)
65
- version = item.at "./version"
66
- return unless version
65
+ item.xpath("./version").map do |v|
66
+ revision_date = v.at("revision-date")&.text
67
+ draft = v.at("draft")&.text
68
+ RelatonBib::BibliographicItem::Version.new revision_date, draft
69
+ end
70
+ end
71
+
72
+ def fetch_edition(item)
73
+ edt = item.at("./edition")
74
+ return unless edt
67
75
 
68
- revision_date = version.at("revision-date")&.text
69
- draft = version.xpath("draft").map &:text
70
- RelatonBib::BibliographicItem::Version.new revision_date, draft
76
+ Edition.new content: edt.text, number: edt[:number]
71
77
  end
72
78
 
73
79
  def fetch_place(item)
@@ -189,10 +195,11 @@ module RelatonBib
189
195
  # @param item [Nokogiri::XML::Element]
190
196
  # @return [Array<RelatonBib::DocumentIdentifier>]
191
197
  def fetch_docid(item)
192
- item.xpath("./docidentifier").map do |did|
193
- primary = true if did[:primary] == "true"
194
- DocumentIdentifier.new(id: did.text, type: did[:type],
195
- scope: did[:scope], primary: primary)
198
+ item.xpath("./docidentifier").map do |id|
199
+ did = id.to_h.transform_keys(&:to_sym)
200
+ did[:id] = id.text
201
+ did[:primary] = id[:primary] == "true" ? true : nil
202
+ DocumentIdentifier.new(**did)
196
203
  end
197
204
  end
198
205
 
data/lib/relaton_bib.rb CHANGED
@@ -36,6 +36,22 @@ module RelatonBib
36
36
  str ? $~[:date] : Date.strptime($~[:date], "%Y")
37
37
  end
38
38
  end
39
+
40
+ #
41
+ # Parse yaml content
42
+ #
43
+ # @param [String] yaml content
44
+ #
45
+ # @return [Hash] data
46
+ #
47
+ def parse_yaml(yaml, classes = [])
48
+ # Newer versions of Psych uses the `permitted_classes:` parameter
49
+ if YAML.method(:safe_load).parameters.map(&:last).include? :permitted_classes
50
+ YAML.safe_load(yaml, permitted_classes: classes)
51
+ else
52
+ YAML.safe_load(yaml, classes)
53
+ end
54
+ end
39
55
  end
40
56
 
41
57
  private
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.11.7
4
+ version: 1.12.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: 2022-06-01 00:00:00.000000000 Z
11
+ date: 2022-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -249,6 +249,7 @@ files:
249
249
  - lib/relaton_bib/document_relation.rb
250
250
  - lib/relaton_bib/document_relation_collection.rb
251
251
  - lib/relaton_bib/document_status.rb
252
+ - lib/relaton_bib/edition.rb
252
253
  - lib/relaton_bib/editorial_group.rb
253
254
  - lib/relaton_bib/formatted_ref.rb
254
255
  - lib/relaton_bib/formatted_string.rb