relaton-bib 1.13.2 → 1.13.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61c7501f15c50370c99043dafc2950b2bb5314725abae9e2c58fc4c2959ee5ac
4
- data.tar.gz: b9bc6f11bd966f6155145cb9f9cc22a9ce1873b549ace92b356c29566ab02139
3
+ metadata.gz: b16ceaaf0f86b9834a58c3a39008309f76d26de2347cb21fd2fef40cabc2fb0d
4
+ data.tar.gz: 98348d372d278546dfa04579b80e6f7b1b9fa289ce794c728716cd73b97787e0
5
5
  SHA512:
6
- metadata.gz: f8f4bdccc1d8d2de570471187b5484d49f18b4b58b1f3c87b91dc97ffbe69a277ed890261ca6cbbe298fb2f61f56ca827cb814e70a18015943e63e6d23209305
7
- data.tar.gz: d343cbca3b0c3c22e3775c13573c0e06b553f557aa03b592cb249c863f23ecde405c794f0cdd594bdc292e9639d56a21a28ffdec50ee9d1c8a3b6a430056274a
6
+ metadata.gz: 97b3b1e729dfcae82196f3aff635c92a199cdae6ca0fa5c338321ef0f86bc3412212b83a3871c1aae7585e71d9db5bc6c6406327e1a7c43cb1f2ca1524e11ebb
7
+ data.tar.gz: eab637a2d826cfa98d7d1cbda52509d05a59949ef7617ef04e066e1abbe4b9326d9a7313db64495925ee345fb1214f08b2381f66acce9a8b3e5e1a21ce95809d
@@ -145,7 +145,7 @@ module RelatonBib
145
145
  # @param language [Arra<String>]
146
146
  # @param script [Array<String>]
147
147
  # @param docstatus [RelatonBib::DocumentStatus, nil]
148
- # @param edition [RelatonBib::Edition, nil]
148
+ # @param edition [RelatonBib::Edition, String, Integer, Float, nil]
149
149
  # @param version [Array<RelatonBib::BibliographicItem::Version>]
150
150
  # @param biblionote [RelatonBib::BiblioNoteCollection]
151
151
  # @param series [Array<RelatonBib::Series>]
@@ -207,7 +207,11 @@ module RelatonBib
207
207
  warn %{[relaton-bib] document type "#{args[:type]}" is invalid.}
208
208
  end
209
209
 
210
- @title = TypedTitleStringCollection.new(args[:title])
210
+ @title = if args[:title].is_a?(TypedTitleStringCollection)
211
+ args[:title]
212
+ else
213
+ TypedTitleStringCollection.new(args[:title])
214
+ end
211
215
 
212
216
  @date = (args[:date] || []).map do |d|
213
217
  d.is_a?(Hash) ? BibliographicDate.new(**d) : d
@@ -236,8 +240,9 @@ module RelatonBib
236
240
  @docnumber = args[:docnumber]
237
241
  @edition = case args[:edition]
238
242
  when Hash then Edition.new(**args[:edition])
239
- when String then Edition.new(content: args[:edition])
240
- else args[:edition]
243
+ when String, Integer, Float
244
+ Edition.new(content: args[:edition].to_s)
245
+ when Edition then args[:edition]
241
246
  end
242
247
  @version = args.fetch :version, []
243
248
  @biblionote = args.fetch :biblionote, BiblioNoteCollection.new([])
@@ -368,7 +373,7 @@ module RelatonBib
368
373
  def to_hash # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
369
374
  hash = {}
370
375
  hash["id"] = id if id
371
- hash["title"] = single_element_array(title) if title&.any?
376
+ hash["title"] = title.to_hash if title&.any?
372
377
  hash["link"] = single_element_array(link) if link&.any?
373
378
  hash["type"] = type if type
374
379
  hash["docid"] = single_element_array(docidentifier) if docidentifier&.any?
@@ -604,10 +609,8 @@ module RelatonBib
604
609
  end
605
610
  end
606
611
 
607
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
608
-
609
612
  # @param [BibTeX::Entry]
610
- def bibtex_author(item) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
613
+ def bibtex_author(item) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/AbcSize
611
614
  authors = contributor.select do |c|
612
615
  c.entity.is_a?(Person) && c.role.map(&:type).include?("author")
613
616
  end.map &:entity
@@ -624,7 +627,7 @@ module RelatonBib
624
627
  end
625
628
 
626
629
  # @param [BibTeX::Entry]
627
- def bibtex_contributor(item) # rubocop:disable Metrics/CyclomaticComplexity
630
+ def bibtex_contributor(item) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
628
631
  contributor.each do |c|
629
632
  rls = c.role.map(&:type)
630
633
  if rls.include?("publisher") then item.publisher = c.entity.name
@@ -638,7 +641,6 @@ module RelatonBib
638
641
  end
639
642
  end
640
643
  end
641
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
642
644
 
643
645
  # @param [BibTeX::Entry]
644
646
  def bibtex_note(item) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize
@@ -724,16 +726,12 @@ module RelatonBib
724
726
  end
725
727
  end
726
728
 
727
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
728
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
729
- # rubocop:disable Style/NestedParenthesizedCalls, Metrics/BlockLength
730
-
731
729
  # @param opts [Hash]
732
730
  # @option opts [Nokogiri::XML::Builder] :builder XML builder
733
731
  # @option opts [Boolean] bibdata
734
732
  # @option opts [Symbol, nil] :date_format (:short), :full
735
733
  # @option opts [String] :lang language
736
- def render_xml(**opts)
734
+ def render_xml(**opts) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
737
735
  root = opts[:bibdata] ? :bibdata : :bibitem
738
736
  xml = opts[:builder].send(root) do |builder|
739
737
  builder.fetched fetched if fetched
@@ -791,7 +789,6 @@ module RelatonBib
791
789
  xml[:type] = type if type
792
790
  xml
793
791
  end
794
- # rubocop:enable Style/NestedParenthesizedCalls, Metrics/BlockLength
795
792
 
796
793
  #
797
794
  # Render BibXML (RFC, BCP)
@@ -799,7 +796,7 @@ module RelatonBib
799
796
  # @param [Nokogiri::XML::Builder] builder
800
797
  # @param [Boolean] include_bibdata
801
798
  #
802
- def render_bibxml(builder, include_keywords)
799
+ def render_bibxml(builder, include_keywords) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
803
800
  target = link.detect { |l| l.type.casecmp("src").zero? } ||
804
801
  link.detect { |l| l.type.casecmp("doi").zero? }
805
802
  bxml = if docnumber&.match(/^BCP/) || (docidentifier.detect(&:primary)&.id ||
@@ -831,7 +828,7 @@ module RelatonBib
831
828
  # @param [Nokogiri::XML::Builder] builder
832
829
  # @param [Boolean] include_keywords
833
830
  #
834
- def render_bibxml_ref(builder, include_keywords)
831
+ def render_bibxml_ref(builder, include_keywords) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
835
832
  builder.reference(**ref_attrs) do |xml|
836
833
  if title.any? || contributor.any? || date.any? || abstract.any? ||
837
834
  editorialgroup&.technical_committee&.any? ||
@@ -861,7 +858,7 @@ module RelatonBib
861
858
  #
862
859
  # @return [Hash<Symbol=>String>] attributes
863
860
  #
864
- def ref_attrs
861
+ def ref_attrs # rubocop:disable Metrics/AbcSize
865
862
  discopes = %w[anchor docName number]
866
863
  attrs = docidentifier.each_with_object({}) do |di, h|
867
864
  next unless discopes.include?(di.scope)
@@ -912,7 +909,7 @@ module RelatonBib
912
909
  #
913
910
  # @param [Nokogiri::XML::Builder] builder xml builder
914
911
  #
915
- def render_date(builder)
912
+ def render_date(builder) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
916
913
  dt = date.detect { |d| d.type == "published" }
917
914
  return unless dt
918
915
 
@@ -933,7 +930,7 @@ module RelatonBib
933
930
  #
934
931
  # @param [Nokogiri::XML::Builder] builder xml builder
935
932
  #
936
- def render_seriesinfo(builder)
933
+ def render_seriesinfo(builder) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
937
934
  docidentifier.each do |di|
938
935
  if BibXMLParser::SERIESINFONAMES.include? di.type
939
936
  builder.seriesInfo(name: di.type, value: di.id)
@@ -954,7 +951,7 @@ module RelatonBib
954
951
  #
955
952
  # @param [Nokogiri::XML::Builder] builder xml builder
956
953
  #
957
- def render_authors(builder)
954
+ def render_authors(builder) # rubocop:disable Metrics/AbcSize
958
955
  contributor.each do |c|
959
956
  builder.author do |xml|
960
957
  xml.parent[:role] = "editor" if c.role.detect { |r| r.type == "editor" }
@@ -972,7 +969,7 @@ module RelatonBib
972
969
  # @param [Nokogiri::XML::Builder] builder xml builder
973
970
  # @param [RelatonBib::ContributionInfo] contrib contributor
974
971
  #
975
- def render_address(builder, contrib)
972
+ def render_address(builder, contrib) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
976
973
  # addr = contrib.entity.contact.reject do |cn|
977
974
  # cn.is_a?(Address) && cn.postcode.nil?
978
975
  # end
@@ -1012,7 +1009,7 @@ module RelatonBib
1012
1009
  # @param [Nokogiri::XML::Builder] builder xml builder
1013
1010
  # @param [RelatonBib::Person] person person
1014
1011
  #
1015
- def render_person(builder, person)
1012
+ def render_person(builder, person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
1016
1013
  render_organization builder, person.affiliation.first&.organization
1017
1014
  if person.name.completename
1018
1015
  builder.parent[:fullname] = person.name.completename.content
@@ -1042,9 +1039,7 @@ module RelatonBib
1042
1039
  # @param [Nokogiri::XML::Builder] builder xml builder
1043
1040
  # @param [RelatonBib::Organization] org organization
1044
1041
  #
1045
- def render_organization(builder, org)
1046
- # return unless org
1047
-
1042
+ def render_organization(builder, org) # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
1048
1043
  ab = org&.abbreviation&.content
1049
1044
  on = org&.name&.first&.content
1050
1045
  orgname = if BibXMLParser::ORGNAMES.key?(ab) then ab
@@ -1053,7 +1048,5 @@ module RelatonBib
1053
1048
  o = builder.organization orgname
1054
1049
  o[:abbrev] = ab if ab
1055
1050
  end
1056
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
1057
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
1058
1051
  end
1059
1052
  end
@@ -9,12 +9,12 @@ module RelatonBib
9
9
  #
10
10
  # Initialize edition.
11
11
  #
12
- # @param [String] content edition
13
- # @param [String, nil] number number
12
+ # @param [String, Integer, Float] content edition
13
+ # @param [String, Integer, Float, nil] number number
14
14
  #
15
15
  def initialize(content:, number: nil)
16
- @content = content
17
- @number = number
16
+ @content = content.to_s
17
+ @number = number&.to_s
18
18
  end
19
19
 
20
20
  #
@@ -83,7 +83,7 @@ module RelatonBib
83
83
 
84
84
  ret[:title] = RelatonBib.array(ret[:title])
85
85
  .reduce(TypedTitleStringCollection.new) do |m, t|
86
- if t.is_a?(Hash) then m << t
86
+ if t.is_a?(Hash) then m << TypedTitleString.new(**t)
87
87
  else
88
88
  m + TypedTitleString.from_string(t)
89
89
  end
@@ -146,13 +146,16 @@ module RelatonBib
146
146
  def docid_hash_to_bib(ret) # rubocop:disable Metrics/AbcSize
147
147
  return unless ret[:docid]
148
148
 
149
- ret[:docid] = RelatonBib.array(ret[:docid])
150
- ret[:docid]&.each_with_index do |id, i|
149
+ ret[:docid] = RelatonBib.array(ret[:docid]).map do |id|
151
150
  id[:type] ||= id[:id].match(/^\w+(?=\s)/)&.to_s
152
- ret[:docid][i] = DocumentIdentifier.new(**id)
151
+ create_docid(**id)
153
152
  end
154
153
  end
155
154
 
155
+ def create_docid(**args)
156
+ DocumentIdentifier.new(**args)
157
+ end
158
+
156
159
  def version_hash_to_bib(ret)
157
160
  return unless ret[:version]
158
161
 
@@ -7,7 +7,7 @@ module RelatonBib
7
7
  attr_reader :hit
8
8
 
9
9
  # @param hit [Hash]
10
- # @param hit_collection [RelatonIso::HitCollection, RelatonNist:HitCollection]
10
+ # @param hit_collection [RelatonBib::HitCollection]
11
11
  def initialize(hit, hit_collection = nil)
12
12
  @hit = hit
13
13
  @hit_collection = hit_collection
@@ -20,11 +20,11 @@ module RelatonBib
20
20
 
21
21
  # @return [String]
22
22
  def inspect
23
- "<#{self.class}:#{format('%<id>#.14x', id: object_id << 1)} "\
24
- "@text=\"#{@hit_collection&.text}\" "\
25
- "@fetched=\"#{!@fetch.nil?}\" "\
26
- "@fullIdentifier=\"#{@fetch&.shortref(nil)}\" "\
27
- "@title=\"#{@hit[:code]}\">"
23
+ "<#{self.class}:#{format('%<id>#.14x', id: object_id << 1)} " \
24
+ "@text=\"#{@hit_collection&.text}\" " \
25
+ "@fetched=\"#{!@fetch.nil?}\" " \
26
+ "@fullIdentifier=\"#{@fetch&.shortref(nil)}\" " \
27
+ "@title=\"#{@hit[:code]}\">"
28
28
  end
29
29
 
30
30
  def fetch
@@ -78,18 +78,13 @@ module RelatonBib
78
78
  def encode(cnt) # rubocop:disable Metrics/MethodLength
79
79
  return unless cnt
80
80
 
81
- # regex = /(?<prf>.*?)(?<xml><(?<tag>\w+)>.*<\/\k<tag>>)(?<sfx>.*)/m
82
- regex = /(?<prf>.*?)(?<xml><(?<tag>\w+)[^>]*(?:>.*<\/\k<tag>)?>)(?<rest>.*)/m
83
- if cnt.match(regex)
84
- prf = Regexp.last_match(:prf).lstrip
85
- xml = Regexp.last_match[:xml]
86
- rest = Regexp.last_match(:rest).rstrip
87
- parts = xml.scan(/\s*<(?<tago>\w+)(?<attrs>[^>]*)>(?:(?<cnt1>.*?)(?=<\/\w+>|<\w+[^>]*>))?|(?<cnt2>.*?)<\/(?<tagc>\w+)>/)
88
- out = scan_xml parts
89
- "#{escp(prf)}#{out}#{encode(rest)}"
90
- else
91
- escp cnt
92
- end
81
+ parts = cnt.scan(%r{
82
+ <(?<tago>\w+)(?<attrs>[^>]*)> | # tag open
83
+ </(?<tagc>\w+)> | # tag close
84
+ (?<cmt><!--.*?-->) | # comment
85
+ (?<cnt>.+?)(?=<|$) # content
86
+ }x)
87
+ scan_xml parts
93
88
  end
94
89
 
95
90
  #
@@ -100,23 +95,32 @@ module RelatonBib
100
95
  # @return [String] output string
101
96
  #
102
97
  def scan_xml(parts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
103
- return "" unless parts.any? && parts.first[0]
104
-
105
- tago, attrs, cnt1, = parts.shift
106
- if tago && tago == parts.first&.last
107
- _, _, _, cnt2, tagc = parts.shift
108
- "<#{tago}#{attrs}>#{escp(cnt1)}#{escp(cnt2)}</#{tagc}>"
109
- elsif tago && attrs && attrs[-1] == "/"
110
- "<#{tago}#{attrs}>"
111
- elsif tago
112
- inr = scan_xml parts
113
- _, _, _, cnt2, tagc = parts.shift
114
- if tago == tagc
115
- "<#{tago}#{attrs}>#{escp(cnt1)}#{inr}#{escp(cnt2)}</#{tagc}>"
116
- else
117
- "#{escp("<#{tago}>#{cnt1}")}#{inr}#{escp("#{cnt2}</#{tagc}>")}"
118
- end
119
- end + scan_xml(parts)
98
+ return "" unless parts.any?
99
+
100
+ out = ""
101
+ while parts.any? && (parts.first[3] || parts.first[4])
102
+ _, _, _, cmt, cnt = parts.shift
103
+ out += "#{cmt}#{escp(cnt)}"
104
+ end
105
+ unless out.empty?
106
+ out += scan_xml(parts) if parts.any? && parts.first[0]
107
+ return out
108
+ end
109
+
110
+ tago, attrs, tagc, = parts.shift
111
+ out = if tago && attrs && attrs[-1] == "/"
112
+ "<#{tago}#{attrs}>"
113
+ elsif tago
114
+ inr = scan_xml parts
115
+ _, _, tagc, = parts.shift
116
+ if tago == tagc
117
+ "<#{tago}#{attrs}>#{inr}</#{tagc}>"
118
+ else
119
+ "#{escp("<#{tago}#{attrs}>")}#{inr}#{escp("</#{tagc}>")}"
120
+ end
121
+ end
122
+ out += scan_xml(parts) if parts.any? && (parts.first[0] || parts.first[3] || parts.first[4])
123
+ out
120
124
  end
121
125
 
122
126
  #
@@ -26,8 +26,8 @@ module RelatonBib
26
26
  end
27
27
 
28
28
  # @return [RelatonBib::TypedTitleStringCollection]
29
- def select
30
- TypedTitleStringCollection.new(titles.select { |t| yield t })
29
+ def select(&block)
30
+ TypedTitleStringCollection.new titles.select(&block)
31
31
  end
32
32
 
33
33
  # @param init [Array, Hash]
@@ -62,6 +62,10 @@ module RelatonBib
62
62
  tl.each { |t| opts[:builder].title { t.to_xml opts[:builder] } }
63
63
  end
64
64
 
65
+ def to_hash
66
+ @array.map(&:to_hash)
67
+ end
68
+
65
69
  #
66
70
  # Add main title ot bibtex entry
67
71
  #
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.13.2".freeze
2
+ VERSION = "1.13.4".freeze
3
3
  end
@@ -376,7 +376,7 @@ module RelatonBib
376
376
  # @return [Array<RelatonBib::FormattedString>]
377
377
  def fetch_abstract(item)
378
378
  item.xpath("./abstract").map do |a|
379
- c = a.inner_html(encoding: "utf-8").strip
379
+ c = a.children.to_xml(encoding: "utf-8").strip
380
380
  FormattedString.new(content: c, language: a[:language],
381
381
  script: a[:script], format: a[:format])
382
382
  end
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.13.2
4
+ version: 1.13.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-09 00:00:00.000000000 Z
11
+ date: 2022-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -280,7 +280,7 @@ homepage: https://github.com/relaton/relaton-bib
280
280
  licenses:
281
281
  - BSD-2-Clause
282
282
  metadata: {}
283
- post_install_message:
283
+ post_install_message:
284
284
  rdoc_options: []
285
285
  require_paths:
286
286
  - lib
@@ -295,8 +295,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
295
295
  - !ruby/object:Gem::Version
296
296
  version: '0'
297
297
  requirements: []
298
- rubygems_version: 3.2.3
299
- signing_key:
298
+ rubygems_version: 3.1.6
299
+ signing_key:
300
300
  specification_version: 4
301
301
  summary: 'RelatonBib: Ruby XMLDOC impementation.'
302
302
  test_files: []