relaton-bib 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2cf0aacc339840ecc4607d6b87e625eaef60ba12ab0fbeffba5876898518f138
4
- data.tar.gz: e41a599b99baaa6d1002cd3ad13803bcffeaa6949840a8cd757db3689716f06b
3
+ metadata.gz: 2f93b20bcbcbd2d652863860202263c53c18c3434dbcb25dadacd6df3215bd07
4
+ data.tar.gz: 58213431b368fdcf86f6391f3a4c5c807379885f8265ab11eaf032256d2c9308
5
5
  SHA512:
6
- metadata.gz: 4f8e1bfe3c6ca8d2ec19733f7ea0f018bae2a102ad92d05bb0983ddf9b7e8715c86c56980ffa106500c2a6971a625143cb6bec2ae9b9a2dd0190fc8b605539c1
7
- data.tar.gz: 721ba6235c7cabc380825ce184f0b2874f1ba519b2f6b9dc44fea52ae061b3bdd18ab56c5db94698535b8db10fe365a88aaf23bcd32a25fa5ce7de96bb8a93b6
6
+ metadata.gz: fb175953b587708dbf1b7ca6b56249ed32a4a14b9b1107eb302cd9578d0a2ed178b8d048a14c20735bf591f9b6f9534b93fd205149b837295754762f2956b63e
7
+ data.tar.gz: 0fc9fa117bd8d87a3ee1f2a9be33e03e6e189f72ceb3194fe39a4e8ad6f8ccee2461f7d378995e11a7f2ff2675ee67ad2ddefbdbb105d59465e9221f0b7e2d7e
@@ -1,24 +1,22 @@
1
1
  module RelatonBib
2
- # module DocumentRelationType
3
- # PARENT = 'parent'
4
- # CHILD = 'child'
5
- # OBSOLETES = 'obsoletes'
6
- # UPDATES = 'updates'
7
- # COMPLEMENTS = 'complements'
8
- # DERIVED_FORM = 'derivedForm'
9
- # ADOPTED_FORM = 'adoptedForm'
10
- # EQUIVALENT = 'equivalent'
11
- # IDENTICAL = 'identical'
12
- # NONEQUIVALENT = 'nonequivalent'
13
- # end
14
-
15
2
  # Documett relation
16
3
  class DocumentRelation
17
4
  include RelatonBib
18
5
 
6
+ TYPES = %w[
7
+ obsoletes obsoletedBy supersedes supersededBy updates updatedBy
8
+ complements derivedFrom translatedFrom hasTranslation adoptedFrom
9
+ equivalent identical nonequivalent includedIn includes instance
10
+ instanceOf partOf hasPart hasDraft draftOf merges splits amends amendedBy
11
+ corrects correctedBy revises revisedBy describes describedBy
12
+ ].freeze
13
+
19
14
  # @return [String]
20
15
  attr_reader :type
21
16
 
17
+ # @return [RelatonBib::FormattedString, NilClass]
18
+ attr_reader :description
19
+
22
20
  # @return [String]
23
21
  # attr_reader :identifier, :url
24
22
 
@@ -32,12 +30,17 @@ module RelatonBib
32
30
  attr_reader :source_locality
33
31
 
34
32
  # @param type [String]
33
+ # @parma description [RelatonBib::FormattedString, NilClass]
35
34
  # @param bibitem [RelatonBib::BibliographicItem, RelatonIso::IsoBibliographicItem]
36
35
  # @param locality [Array<RelatonBib::Locality, RelatonBib::LocalityStack>]
37
36
  # @param source_locality [Array<RelatonBib::SourceLocality, RelatonBib::SourceLocalityStack>]
38
- def initialize(type:, bibitem:, locality: [], source_locality: [])
37
+ def initialize(type:, description: nil, bibitem:, locality: [], source_locality: [])
39
38
  type = "obsoletes" if type == "Now withdrawn"
39
+ unless TYPES.include? type
40
+ warn "[relaton-bib] WARNING: invalid relation type: #{type}"
41
+ end
40
42
  @type = type
43
+ @description = description
41
44
  @locality = locality
42
45
  @source_locality = source_locality
43
46
  @bibitem = bibitem
@@ -48,6 +51,7 @@ module RelatonBib
48
51
  opts.delete :bibdata
49
52
  opts.delete :note
50
53
  builder.relation(type: type) do
54
+ builder.description { description.to_xml builder } if description
51
55
  bibitem.to_xml(builder, **opts.merge(embedded: true))
52
56
  locality.each { |l| l.to_xml builder }
53
57
  source_locality.each { |l| l.to_xml builder }
@@ -57,6 +61,7 @@ module RelatonBib
57
61
  # @return [Hash]
58
62
  def to_hash
59
63
  hash = { "type" => type, "bibitem" => bibitem.to_hash }
64
+ hash["description"] = description.to_hash if description
60
65
  hash["locality"] = single_element_array(locality) if locality&.any?
61
66
  if source_locality&.any?
62
67
  hash["source_locality"] = single_element_array(source_locality)
@@ -23,9 +23,12 @@ module RelatonBib
23
23
  @array = relation.map { |r| r.is_a?(Hash) ? DocumentRelation.new(r) : r }
24
24
  end
25
25
 
26
+ # @todo We don't have replace type anymore. Suppose we should update this
27
+ # method or delete it.
28
+ #
26
29
  # @return [RelatonBib::DocRelationCollection]
27
- def replaces
28
- DocRelationCollection.new @array.select { |r| r.type == "replace" }
29
- end
30
+ # def replaces
31
+ # DocRelationCollection.new @array.select { |r| r.type == "replace" }
32
+ # end
30
33
  end
31
34
  end
@@ -258,6 +258,9 @@ module RelatonBib
258
258
 
259
259
  ret[:relation] = array(ret[:relation])
260
260
  ret[:relation]&.each do |r|
261
+ if r[:description]
262
+ r[:description] = FormattedString.new r[:description]
263
+ end
261
264
  relation_bibitem_hash_to_bib(r)
262
265
  relation_locality_hash_to_bib(r)
263
266
  relation_source_locality_hash_to_bib(r)
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.0.0".freeze
2
+ VERSION = "1.0.1".freeze
3
3
  end
@@ -91,12 +91,16 @@ module RelatonBib
91
91
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
92
92
 
93
93
  def fetch_series(item)
94
- item.xpath("./series").map do |sr|
94
+ item.xpath("./series").reduce([]) do |mem, sr|
95
95
  abbr = sr.at "abbreviation"
96
96
  abbreviation = abbr ? LocalizedString.new(abbr.text, abbr[:language], abbr[:script]) : nil
97
- Series.new(
98
- type: sr[:type], formattedref: fref(sr),
99
- title: ttitle(sr.at("title")), place: sr.at("place")&.text,
97
+ formattedref = fref(sr)
98
+ title = ttitle(sr.at("title"))
99
+ next mem unless formattedref || title
100
+
101
+ mem << Series.new(
102
+ type: sr[:type], formattedref: formattedref,
103
+ title: title, place: sr.at("place")&.text,
100
104
  organization: sr.at("organization")&.text,
101
105
  abbreviation: abbreviation, from: sr.at("from")&.text,
102
106
  to: sr.at("to")&.text, number: sr.at("number")&.text,
@@ -310,6 +314,7 @@ module RelatonBib
310
314
  item.xpath("./relation").map do |rel|
311
315
  DocumentRelation.new(
312
316
  type: rel[:type]&.empty? ? nil : rel[:type],
317
+ description: relation_description(rel),
313
318
  bibitem: bib_item(item_data(rel.at("./bibitem"))),
314
319
  locality: localities(rel),
315
320
  source_locality: source_localities(rel),
@@ -317,6 +322,16 @@ module RelatonBib
317
322
  end
318
323
  end
319
324
 
325
+ # @param rel [Nokogiri::XML::Element]
326
+ # @return [RelatonBib::FormattedString, NilClass]
327
+ def relation_description(rel)
328
+ d = rel.at "./description"
329
+ return unless d
330
+
331
+ FormattedString.new(content: d.text, language: d[:language],
332
+ script: d[:script], format: d[:format])
333
+ end
334
+
320
335
  # @param item_hash [Hash]
321
336
  # @return [RelatonBib::BibliographicItem]
322
337
  def bib_item(item_hash)
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.0.0
4
+ version: 1.0.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-04-25 00:00:00.000000000 Z
11
+ date: 2020-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debase