relaton-bib 1.13.2 → 1.13.3
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 +4 -4
- data/lib/relaton_bib/bibliographic_item.rb +18 -26
- data/lib/relaton_bib/hash_converter.rb +7 -4
- data/lib/relaton_bib/hit.rb +6 -6
- data/lib/relaton_bib/localized_string.rb +33 -29
- data/lib/relaton_bib/typed_title_string.rb +6 -2
- data/lib/relaton_bib/version.rb +1 -1
- data/lib/relaton_bib/xml_parser.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca70214e52f3a00a9388de24a1e07fa6464e0cb23831fd14775ce0e29c929fdf
|
4
|
+
data.tar.gz: 33cafac4c23e9dc57f102982bffbea20c25420f89471f164a0f875e4e6a74e26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5eb2c4f5b7c13337a0e1f560d69ad140f91ea49405c3a4d876110bcdab32e532043a65187ca5fa6973c6cb0cf0240c285430a58d32338d186da882632194b2d
|
7
|
+
data.tar.gz: 3fd3d4b199c1c190c4920c7daba0e73979a6e82ee24648a84ab3057e2cee08345db9cc929ba324773a55d0e1fe4160ca5af2320a2e297c52dfcbace78bbcd282
|
@@ -207,7 +207,11 @@ module RelatonBib
|
|
207
207
|
warn %{[relaton-bib] document type "#{args[:type]}" is invalid.}
|
208
208
|
end
|
209
209
|
|
210
|
-
@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
|
@@ -368,7 +372,7 @@ module RelatonBib
|
|
368
372
|
def to_hash # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
369
373
|
hash = {}
|
370
374
|
hash["id"] = id if id
|
371
|
-
hash["title"] =
|
375
|
+
hash["title"] = title.to_hash if title&.any?
|
372
376
|
hash["link"] = single_element_array(link) if link&.any?
|
373
377
|
hash["type"] = type if type
|
374
378
|
hash["docid"] = single_element_array(docidentifier) if docidentifier&.any?
|
@@ -604,10 +608,8 @@ module RelatonBib
|
|
604
608
|
end
|
605
609
|
end
|
606
610
|
|
607
|
-
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
608
|
-
|
609
611
|
# @param [BibTeX::Entry]
|
610
|
-
def bibtex_author(item) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
612
|
+
def bibtex_author(item) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/AbcSize
|
611
613
|
authors = contributor.select do |c|
|
612
614
|
c.entity.is_a?(Person) && c.role.map(&:type).include?("author")
|
613
615
|
end.map &:entity
|
@@ -624,7 +626,7 @@ module RelatonBib
|
|
624
626
|
end
|
625
627
|
|
626
628
|
# @param [BibTeX::Entry]
|
627
|
-
def bibtex_contributor(item) # rubocop:disable Metrics/CyclomaticComplexity
|
629
|
+
def bibtex_contributor(item) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize, Metrics/MethodLength
|
628
630
|
contributor.each do |c|
|
629
631
|
rls = c.role.map(&:type)
|
630
632
|
if rls.include?("publisher") then item.publisher = c.entity.name
|
@@ -638,7 +640,6 @@ module RelatonBib
|
|
638
640
|
end
|
639
641
|
end
|
640
642
|
end
|
641
|
-
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
642
643
|
|
643
644
|
# @param [BibTeX::Entry]
|
644
645
|
def bibtex_note(item) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize
|
@@ -724,16 +725,12 @@ module RelatonBib
|
|
724
725
|
end
|
725
726
|
end
|
726
727
|
|
727
|
-
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
728
|
-
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
729
|
-
# rubocop:disable Style/NestedParenthesizedCalls, Metrics/BlockLength
|
730
|
-
|
731
728
|
# @param opts [Hash]
|
732
729
|
# @option opts [Nokogiri::XML::Builder] :builder XML builder
|
733
730
|
# @option opts [Boolean] bibdata
|
734
731
|
# @option opts [Symbol, nil] :date_format (:short), :full
|
735
732
|
# @option opts [String] :lang language
|
736
|
-
def render_xml(**opts)
|
733
|
+
def render_xml(**opts) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
737
734
|
root = opts[:bibdata] ? :bibdata : :bibitem
|
738
735
|
xml = opts[:builder].send(root) do |builder|
|
739
736
|
builder.fetched fetched if fetched
|
@@ -791,7 +788,6 @@ module RelatonBib
|
|
791
788
|
xml[:type] = type if type
|
792
789
|
xml
|
793
790
|
end
|
794
|
-
# rubocop:enable Style/NestedParenthesizedCalls, Metrics/BlockLength
|
795
791
|
|
796
792
|
#
|
797
793
|
# Render BibXML (RFC, BCP)
|
@@ -799,7 +795,7 @@ module RelatonBib
|
|
799
795
|
# @param [Nokogiri::XML::Builder] builder
|
800
796
|
# @param [Boolean] include_bibdata
|
801
797
|
#
|
802
|
-
def render_bibxml(builder, include_keywords)
|
798
|
+
def render_bibxml(builder, include_keywords) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
803
799
|
target = link.detect { |l| l.type.casecmp("src").zero? } ||
|
804
800
|
link.detect { |l| l.type.casecmp("doi").zero? }
|
805
801
|
bxml = if docnumber&.match(/^BCP/) || (docidentifier.detect(&:primary)&.id ||
|
@@ -831,7 +827,7 @@ module RelatonBib
|
|
831
827
|
# @param [Nokogiri::XML::Builder] builder
|
832
828
|
# @param [Boolean] include_keywords
|
833
829
|
#
|
834
|
-
def render_bibxml_ref(builder, include_keywords)
|
830
|
+
def render_bibxml_ref(builder, include_keywords) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
835
831
|
builder.reference(**ref_attrs) do |xml|
|
836
832
|
if title.any? || contributor.any? || date.any? || abstract.any? ||
|
837
833
|
editorialgroup&.technical_committee&.any? ||
|
@@ -861,7 +857,7 @@ module RelatonBib
|
|
861
857
|
#
|
862
858
|
# @return [Hash<Symbol=>String>] attributes
|
863
859
|
#
|
864
|
-
def ref_attrs
|
860
|
+
def ref_attrs # rubocop:disable Metrics/AbcSize
|
865
861
|
discopes = %w[anchor docName number]
|
866
862
|
attrs = docidentifier.each_with_object({}) do |di, h|
|
867
863
|
next unless discopes.include?(di.scope)
|
@@ -912,7 +908,7 @@ module RelatonBib
|
|
912
908
|
#
|
913
909
|
# @param [Nokogiri::XML::Builder] builder xml builder
|
914
910
|
#
|
915
|
-
def render_date(builder)
|
911
|
+
def render_date(builder) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
916
912
|
dt = date.detect { |d| d.type == "published" }
|
917
913
|
return unless dt
|
918
914
|
|
@@ -933,7 +929,7 @@ module RelatonBib
|
|
933
929
|
#
|
934
930
|
# @param [Nokogiri::XML::Builder] builder xml builder
|
935
931
|
#
|
936
|
-
def render_seriesinfo(builder)
|
932
|
+
def render_seriesinfo(builder) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
937
933
|
docidentifier.each do |di|
|
938
934
|
if BibXMLParser::SERIESINFONAMES.include? di.type
|
939
935
|
builder.seriesInfo(name: di.type, value: di.id)
|
@@ -954,7 +950,7 @@ module RelatonBib
|
|
954
950
|
#
|
955
951
|
# @param [Nokogiri::XML::Builder] builder xml builder
|
956
952
|
#
|
957
|
-
def render_authors(builder)
|
953
|
+
def render_authors(builder) # rubocop:disable Metrics/AbcSize
|
958
954
|
contributor.each do |c|
|
959
955
|
builder.author do |xml|
|
960
956
|
xml.parent[:role] = "editor" if c.role.detect { |r| r.type == "editor" }
|
@@ -972,7 +968,7 @@ module RelatonBib
|
|
972
968
|
# @param [Nokogiri::XML::Builder] builder xml builder
|
973
969
|
# @param [RelatonBib::ContributionInfo] contrib contributor
|
974
970
|
#
|
975
|
-
def render_address(builder, contrib)
|
971
|
+
def render_address(builder, contrib) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
976
972
|
# addr = contrib.entity.contact.reject do |cn|
|
977
973
|
# cn.is_a?(Address) && cn.postcode.nil?
|
978
974
|
# end
|
@@ -1012,7 +1008,7 @@ module RelatonBib
|
|
1012
1008
|
# @param [Nokogiri::XML::Builder] builder xml builder
|
1013
1009
|
# @param [RelatonBib::Person] person person
|
1014
1010
|
#
|
1015
|
-
def render_person(builder, person)
|
1011
|
+
def render_person(builder, person) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
1016
1012
|
render_organization builder, person.affiliation.first&.organization
|
1017
1013
|
if person.name.completename
|
1018
1014
|
builder.parent[:fullname] = person.name.completename.content
|
@@ -1042,9 +1038,7 @@ module RelatonBib
|
|
1042
1038
|
# @param [Nokogiri::XML::Builder] builder xml builder
|
1043
1039
|
# @param [RelatonBib::Organization] org organization
|
1044
1040
|
#
|
1045
|
-
def render_organization(builder, org)
|
1046
|
-
# return unless org
|
1047
|
-
|
1041
|
+
def render_organization(builder, org) # rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
1048
1042
|
ab = org&.abbreviation&.content
|
1049
1043
|
on = org&.name&.first&.content
|
1050
1044
|
orgname = if BibXMLParser::ORGNAMES.key?(ab) then ab
|
@@ -1053,7 +1047,5 @@ module RelatonBib
|
|
1053
1047
|
o = builder.organization orgname
|
1054
1048
|
o[:abbrev] = ab if ab
|
1055
1049
|
end
|
1056
|
-
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
1057
|
-
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
1058
1050
|
end
|
1059
1051
|
end
|
@@ -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
|
-
|
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
|
|
data/lib/relaton_bib/hit.rb
CHANGED
@@ -7,7 +7,7 @@ module RelatonBib
|
|
7
7
|
attr_reader :hit
|
8
8
|
|
9
9
|
# @param hit [Hash]
|
10
|
-
# @param hit_collection [
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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?
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
_, _, _,
|
108
|
-
"
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
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
|
#
|
data/lib/relaton_bib/version.rb
CHANGED
@@ -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.
|
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.
|
4
|
+
version: 1.13.3
|
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-
|
11
|
+
date: 2022-09-15 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.
|
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: []
|