relaton-bib 1.9.0 → 1.9.4

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: dd7a8d6375ee7685203318f381c2f2b83c108460a2b9df8baceffe069e2e9915
4
- data.tar.gz: 86b951c16a4f547c343347e001cbe06380fda97fccfb6e4ee3a58b92af81cc95
3
+ metadata.gz: 3f54471913accf8362c7e96a1679e62e7f73092d12cb24156797837084371f06
4
+ data.tar.gz: b9c94af722de0e6fd41064aa1a15a7f604698f525c24bb611ddc3430eea0b4ac
5
5
  SHA512:
6
- metadata.gz: a342b2f2ea573d678746d3d219e0848beb5e12f55aca30004c19884e033f8347416f41d40ce188a908a06efdb85d0637ac0b90a83bede39d78a366bbe52778fc
7
- data.tar.gz: 36c96c90ecc6563973520f1991ad1322b6cefce62a5c7d8bbd0bd9bf4c66c6dcb585ba9cc5c00f8d2c67f582d0a5f02f220656d27cb54b4c4396100085057a7f
6
+ metadata.gz: 38dccc66a7bf1f7b49b471d1f3dd97e75a925d86dde075a1778b065bcfd6767406e26e5c38a954d17ea824ba06a43ee4eacada09ceeabf91f38615fccd480dc0
7
+ data.tar.gz: 8339ccfb65c672dd5f1a3928696cc1ca9e0f055b605c4ec631046a668603f756bd1f7e56547863453cddfdde3950538d48c2e6ad6990cbefbdb459bd6ce31d48
data/README.adoc CHANGED
@@ -416,6 +416,45 @@ title.format:: text/plain
416
416
  ...
417
417
  ----
418
418
 
419
+ === Export bibliographic item to BibXML (RFC)
420
+
421
+ [source,ruby]
422
+ ----
423
+ item.to_bibxml
424
+ <reference anchor="ISOTC211" target="https://www.iso.org/standard/53798.html">
425
+ <front>
426
+ <title>Geographic information</title>
427
+ <seriesInfo name="DOI" value="10.17487/rfc1149"/>
428
+ <seriesInfo name="Internet-Draft" value="draft-ietf-somewg-someprotocol-07"/>
429
+ <seriesInfo name="RFC" value="4"/>
430
+ <author>
431
+ <organization abbrev="ISO">International Organization for Standardization</organization>
432
+ </author>
433
+ <author fullname="A. Bierman">
434
+ <organization abbrev="IETF">IETF</organization>
435
+ <address>
436
+ <postal>123456</postal>
437
+ <phone>223322</phone>
438
+ </address>
439
+ </author>
440
+ <author role="editor">
441
+ <organization abbrev="IETF">IETF</organization>
442
+ </author>
443
+ <author initials="A." surname="Bierman">
444
+ <organization abbrev="IETF">IETF</organization>
445
+ <address>
446
+ <postal>123456</postal>
447
+ <phone>223322</phone>
448
+ </address>
449
+ </author>
450
+ <author>
451
+ <organization>Institution</organization>
452
+ </author>
453
+ <date year="2014" month="April" day="1"/>
454
+ </front>
455
+ </reference>
456
+ ----
457
+
419
458
  == Development
420
459
 
421
460
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -429,4 +468,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/metano
429
468
  == License
430
469
 
431
470
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
432
-
@@ -325,6 +325,23 @@ module RelatonBib
325
325
  end
326
326
  end
327
327
 
328
+ #
329
+ # Render BibXML (RFC)
330
+ #
331
+ # @param [Nokogiri::XML::Builder, nil] builder
332
+ #
333
+ # @return [String] <description>
334
+ #
335
+ def to_bibxml(builder = nil)
336
+ if builder
337
+ render_bibxml builder
338
+ else
339
+ Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
340
+ render_bibxml xml
341
+ end
342
+ end.doc.root.to_xml
343
+ end
344
+
328
345
  # @return [Hash]
329
346
  def to_hash # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
330
347
  hash = {}
@@ -740,8 +757,107 @@ module RelatonBib
740
757
  xml[:type] = type if type
741
758
  xml
742
759
  end
760
+ # rubocop:enable Style/NestedParenthesizedCalls, Metrics/BlockLength
761
+
762
+ #
763
+ # Render BibXML (RFC)
764
+ #
765
+ # @param [Nokogiri::XML::Builder] builder
766
+ #
767
+ def render_bibxml(builder)
768
+ target = link.detect { |l| l.type == "src" } || link.detect { |l| l.type == "doi" }
769
+ bxml = builder.reference(anchor: id) do |xml|
770
+ xml.front do
771
+ xml.title title[0].title.content if title.any?
772
+ render_seriesinfo xml
773
+ render_authors xml
774
+ render_date xml
775
+ end
776
+ end
777
+ bxml[:target] = target.content.to_s if target
778
+ end
779
+
780
+ def render_date(builder)
781
+ dt = date.detect { |d| d.type == "published" }
782
+ return unless dt
783
+
784
+ elm = builder.date
785
+ y = dt.on(:year) || dt.from(:year) || dt.to(:year)
786
+ elm[:year] = y if y
787
+ m = dt.on(:month) || dt.from(:month) || dt.to(:month)
788
+ elm[:month] = Date::MONTHNAMES[m] if m
789
+ d = dt.on(:day) || dt.from(:day) || dt.to(:day)
790
+ elm[:day] = d if d
791
+ end
792
+
793
+ def render_seriesinfo(builder)
794
+ names = ["DOI", "Internet-Draft"]
795
+ docidentifier.each do |di|
796
+ if names.include? di.type
797
+ builder.seriesInfo(name: di.type, value: di.id)
798
+ end
799
+ end
800
+ snames = ["ANSI", "BCP", "RFC", "STD"]
801
+ series.each do |s|
802
+ next unless s.title && snames.include?(s.title.title.to_s)
803
+
804
+ si = builder.seriesInfo(name: s.title.title.to_s)
805
+ si[:value] = s.number if s.number
806
+ end
807
+ end
808
+
809
+ def render_authors(builder)
810
+ contributor.each do |c|
811
+ builder.author do |xml|
812
+ xml.parent[:role] = "editor" if c.role.detect { |r| r.type == "editor" }
813
+ if c.entity.is_a?(Person) then render_person xml, c.entity
814
+ else render_organization xml, c.entity
815
+ end
816
+ render_address xml, c
817
+ end
818
+ end
819
+ end
820
+
821
+ def render_address(builder, contrib)
822
+ addr = contrib.entity.contact.reject do |cn|
823
+ cn.is_a?(Address) && cn.postcode.nil?
824
+ end
825
+ if addr.any?
826
+ builder.address do |xml|
827
+ address = addr.detect { |cn| cn.is_a? Address }
828
+ xml.postal address.postcode if address.postcode
829
+ render_contact xml, addr
830
+ end
831
+ end
832
+ end
833
+
834
+ def render_contact(builder, addr)
835
+ %w[phone email uri].each do |type|
836
+ cont = addr.detect { |cn| cn.is_a?(Contact) && cn.type == type }
837
+ builder.phone cont.value if cont
838
+ end
839
+ end
840
+
841
+ def render_person(builder, person)
842
+ render_organization builder, person.affiliation.first&.organization
843
+ if person.name.completename
844
+ builder.parent[:fullname] = person.name.completename
845
+ end
846
+ if person.name.initial.any?
847
+ builder.parent[:initials] = person.name.initial.map(&:content).join
848
+ end
849
+ if person.name.surname
850
+ builder.parent[:surname] = person.name.surname
851
+ end
852
+ end
853
+
854
+ def render_organization(builder, org)
855
+ return unless org
856
+
857
+ o = builder.organization org.name.first&.content
858
+ o[:abbrev] = org.abbreviation if org.abbreviation
859
+ end
743
860
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
744
861
  # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
745
- # rubocop:enable Style/NestedParenthesizedCalls, Metrics/BlockLength
746
862
  end
747
863
  end
@@ -7,7 +7,7 @@ module RelatonBib
7
7
  # @return [Array<RelatonBib::TechnicalCommittee>]
8
8
  attr_accessor :technical_committee
9
9
 
10
- # @param technical_committee [Array<RelatonBib::TecnicalCommittee>]
10
+ # @param technical_committee [Array<RelatonBib::TechnicalCommittee>]
11
11
  def initialize(technical_committee)
12
12
  @technical_committee = technical_committee
13
13
  end
@@ -207,6 +207,7 @@ module RelatonBib
207
207
  org[:subdivision] = array(org[:subdivision]).map do |sd|
208
208
  LocalizedString.new sd
209
209
  end
210
+ org[:contact] = contacts_hash_to_bib(org)
210
211
  org
211
212
  end
212
213
 
@@ -256,10 +257,10 @@ module RelatonBib
256
257
  end
257
258
  end
258
259
 
259
- def contacts_hash_to_bib(person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
260
- return [] unless person[:contact]
260
+ def contacts_hash_to_bib(entity) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
261
+ return [] unless entity[:contact]
261
262
 
262
- array(person[:contact]).map do |a|
263
+ array(entity[:contact]).map do |a|
263
264
  if a[:city] || a[:country]
264
265
  RelatonBib::Address.new(
265
266
  street: Array(a[:street]), city: a[:city], postcode: a[:postcode],
@@ -21,14 +21,15 @@ module RelatonBib
21
21
  if content.is_a?(Array) && content.none?
22
22
  raise ArgumentError, "LocalizedString content is empty"
23
23
  end
24
+
24
25
  @language = language.is_a?(String) ? [language] : language
25
26
  @script = script.is_a?(String) ? [script] : script
26
27
  @content = if content.is_a?(Array)
27
28
  content.map do |c|
28
- if c.is_a?(Hash)
29
+ case c
30
+ when Hash
29
31
  LocalizedString.new c[:content], c[:language], c[:script]
30
- elsif c.is_a?(String)
31
- LocalizedString.new c
32
+ when String then LocalizedString.new c
32
33
  else c
33
34
  end
34
35
  end
@@ -38,7 +39,7 @@ module RelatonBib
38
39
 
39
40
  # @return [String]
40
41
  def to_s
41
- content.is_a?(String) ? content : content.first.to_s
42
+ content.is_a?(Array) ? content.first.to_s : content.to_s
42
43
  end
43
44
 
44
45
  # @return [TrueClass, FalseClass]
@@ -99,7 +99,7 @@ module RelatonBib
99
99
  builder.abbreviation { |a| abbreviation.to_xml a } if abbreviation
100
100
  builder.uri url if uri
101
101
  identifier.each { |identifier| identifier.to_xml builder }
102
- super
102
+ super builder
103
103
  end
104
104
  end
105
105
 
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.9.0".freeze
2
+ VERSION = "1.9.4".freeze
3
3
  end
@@ -297,7 +297,7 @@ module RelatonBib
297
297
 
298
298
  def name_part(person, part)
299
299
  person.xpath("./name/#{part}").map do |np|
300
- LocalizedString.new np.text, np[:language]
300
+ LocalizedString.new np.text, np[:language], np[:script]
301
301
  end
302
302
  end
303
303
 
data/lib/relaton_bib.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "forwardable"
2
+ require "yaml"
2
3
  require "relaton_bib/version"
3
4
  require "relaton_bib/deep_dup"
4
5
  require "relaton_bib/localized_string"
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.9.0
4
+ version: 1.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-26 00:00:00.000000000 Z
11
+ date: 2021-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug