relaton-bib 1.9.3 → 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: c432bbee2d1bcf2b1c6b0d23abdeb2d4d017ab6bd5cb317b3d88cd82a304c3f8
4
- data.tar.gz: 8d8ed4ea374b4c5e978608e97a46dd98e98d024ee8ab07835fbede899dee9a33
3
+ metadata.gz: 3f54471913accf8362c7e96a1679e62e7f73092d12cb24156797837084371f06
4
+ data.tar.gz: b9c94af722de0e6fd41064aa1a15a7f604698f525c24bb611ddc3430eea0b4ac
5
5
  SHA512:
6
- metadata.gz: b94f4f9ff22469817a83635e410d49011b19c65ae1cd1c03af7a9f96a666bad564812440fd73c5dfaa6ff98a81ddcfaff970c8e7c85f4a247ce1fca15440c5c1
7
- data.tar.gz: 0fa9dd7153a13a91e7663626058f11c7152b990aff1e016ce093f8e394a5166fac72ee726aad4ce89b20cbb90a7e5b35f65bdaa95d3f7fb74c2bf5b90de0960b
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
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.9.3".freeze
2
+ VERSION = "1.9.4".freeze
3
3
  end
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.3
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-09-24 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