relaton-bib 1.0.3 → 1.0.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 +4 -4
- data/lib/relaton_bib/bibtex_parser.rb +22 -20
- data/lib/relaton_bib/document_relation.rb +12 -5
- data/lib/relaton_bib/formatted_string.rb +3 -3
- data/lib/relaton_bib/hash_converter.rb +3 -2
- data/lib/relaton_bib/localized_string.rb +33 -12
- data/lib/relaton_bib/typed_title_string.rb +1 -1
- data/lib/relaton_bib/version.rb +1 -1
- data/lib/relaton_bib/xml_parser.rb +5 -1
- data/relaton-bib.gemspec +3 -3
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57c6be55831892ce4762c2a9e8f4526cc6e7efadb3f99b0a1cf0cea7219ed001
|
4
|
+
data.tar.gz: ae71060872bb8fb1630a66fda9a7af01c9dbc5497efbe16669193fbca4c426a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3074c5b9dc2ee9e963b766e7428f1c56aa2cd961e11618e4eea8e0c0f5d20e35bd9d16a1ede8f821f2840bb0de4cf1e053666c486dfe6f6927d07999ad5c9b6
|
7
|
+
data.tar.gz: 9b5f8e1c773a95438942b6a69e13ce0f82e4fb194c364d141580d38726adc2329a00fc8b5b2ac96197591ae8993a1886148313b75676ca2b32865b1d7b17fbbc
|
@@ -147,17 +147,16 @@ module RelatonBib
|
|
147
147
|
# @param bibtex [BibTeX::Entry]
|
148
148
|
# @return [Array<RelatonBib::BiblioNote>]
|
149
149
|
def fetch_note(bibtex)
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
150
|
+
bibtex.select do |k, _v|
|
151
|
+
%i[annote howpublished comment note content].include? k
|
152
|
+
end.reduce([]) do |mem, note|
|
153
|
+
type = case note[0]
|
154
|
+
when :note then nil
|
155
|
+
when :content then "tableOfContents"
|
156
|
+
else note[0].to_s
|
157
|
+
end
|
158
|
+
mem << BiblioNote.new(type: type, content: note[1].to_s)
|
155
159
|
end
|
156
|
-
|
157
|
-
note << BiblioNote.new(type: "comment", content: bibtex.comment.to_s) if bibtex["comment"]
|
158
|
-
note << BiblioNote.new(content: bibtex.note.to_s) if bibtex["note"]
|
159
|
-
note << BiblioNote.new(type: "tableOfContents", content: bibtex["content"]) if bibtex["content"]
|
160
|
-
note
|
161
160
|
end
|
162
161
|
|
163
162
|
# @param bibtex [BibTeX::Entry]
|
@@ -172,16 +171,19 @@ module RelatonBib
|
|
172
171
|
# @param bibtex [BibTeX::Entry]
|
173
172
|
# @return [Array<RelatonBib::BibItemLocality>]
|
174
173
|
def fetch_extent(bibtex)
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
174
|
+
bibtex.select do |k, _v|
|
175
|
+
%i[chapter pages volume].include? k
|
176
|
+
end.reduce([]) do |mem, loc|
|
177
|
+
if loc[0] == :pages
|
178
|
+
type = "page"
|
179
|
+
from, to = loc[1].to_s.split "-"
|
180
|
+
else
|
181
|
+
type = loc[0].to_s
|
182
|
+
from = loc[1].to_s
|
183
|
+
to = nil
|
184
|
+
end
|
185
|
+
mem << BibItemLocality.new(type, from, to)
|
181
186
|
end
|
182
|
-
|
183
|
-
extent << BibItemLocality.new("volume", bibtex.volume.to_s) if bibtex["volume"]
|
184
|
-
extent
|
185
187
|
end
|
186
188
|
|
187
189
|
# @param bibtex [BibTeX::Entry]
|
@@ -192,7 +194,7 @@ module RelatonBib
|
|
192
194
|
series << Series.new(
|
193
195
|
type: "journal",
|
194
196
|
title: TypedTitleString.new(content: bibtex.journal.to_s),
|
195
|
-
number: bibtex["number"]&.to_s
|
197
|
+
number: bibtex["number"]&.to_s,
|
196
198
|
)
|
197
199
|
end
|
198
200
|
|
@@ -31,16 +31,20 @@ module RelatonBib
|
|
31
31
|
# @return [Array<RelatonBib::Locality, RelatonBib::LocalityStack>]
|
32
32
|
attr_reader :locality
|
33
33
|
|
34
|
-
# @return [Array<RelatonBib::SourceLocality,
|
34
|
+
# @return [Array<RelatonBib::SourceLocality,
|
35
|
+
# RelatonBib::SourceLocalityStack>]
|
35
36
|
attr_reader :source_locality
|
36
37
|
|
37
38
|
# @param type [String]
|
38
39
|
# @parma description [RelatonBib::FormattedString, NilClass]
|
39
|
-
# @param bibitem [RelatonBib::BibliographicItem,
|
40
|
+
# @param bibitem [RelatonBib::BibliographicItem,
|
41
|
+
# RelatonIso::IsoBibliographicItem]
|
40
42
|
# @param locality [Array<RelatonBib::Locality, RelatonBib::LocalityStack>]
|
41
|
-
# @param source_locality [Array<RelatonBib::SourceLocality,
|
42
|
-
|
43
|
-
|
43
|
+
# @param source_locality [Array<RelatonBib::SourceLocality,
|
44
|
+
# RelatonBib::SourceLocalityStack>]
|
45
|
+
def initialize(type:, description: nil, bibitem:, locality: [],
|
46
|
+
source_locality: [])
|
47
|
+
type = "obsoletes" if type == "Now withdrawn"
|
44
48
|
unless TYPES.include? type
|
45
49
|
warn "[relaton-bib] WARNING: invalid relation type: #{type}"
|
46
50
|
end
|
@@ -51,6 +55,8 @@ module RelatonBib
|
|
51
55
|
@bibitem = bibitem
|
52
56
|
end
|
53
57
|
|
58
|
+
# rubocop:disable Metrics/AbcSize
|
59
|
+
|
54
60
|
# @param builder [Nokogiri::XML::Builder]
|
55
61
|
def to_xml(builder, **opts)
|
56
62
|
opts.delete :bibdata
|
@@ -62,6 +68,7 @@ module RelatonBib
|
|
62
68
|
source_locality.each { |l| l.to_xml builder }
|
63
69
|
end
|
64
70
|
end
|
71
|
+
# rubocop:enable Metrics/AbcSize
|
65
72
|
|
66
73
|
# @return [Hash]
|
67
74
|
def to_hash
|
@@ -12,7 +12,7 @@ module RelatonBib
|
|
12
12
|
# @return [String]
|
13
13
|
attr_reader :format
|
14
14
|
|
15
|
-
# @param content [String]
|
15
|
+
# @param content [String, Array<RelatonBib::LocalizedString>]
|
16
16
|
# @param language [String, NilClass] language code Iso639
|
17
17
|
# @param script [String, NilClass] script code Iso15924
|
18
18
|
# @param format [String] the content type
|
@@ -36,8 +36,8 @@ module RelatonBib
|
|
36
36
|
hash = super
|
37
37
|
return hash unless format
|
38
38
|
|
39
|
-
hash = { "content" => hash }
|
40
|
-
hash["format"] = format
|
39
|
+
hash = { "content" => hash } unless hash.is_a? Hash
|
40
|
+
hash["format"] = format
|
41
41
|
hash
|
42
42
|
end
|
43
43
|
end
|
@@ -168,7 +168,8 @@ module RelatonBib
|
|
168
168
|
def stage(stg)
|
169
169
|
return unless stg
|
170
170
|
|
171
|
-
|
171
|
+
args = stg.is_a?(String) ? { value: stg } : stg
|
172
|
+
DocumentStatus::Stage.new(**args)
|
172
173
|
end
|
173
174
|
|
174
175
|
def contributors_hash_to_bib(ret)
|
@@ -329,7 +330,7 @@ module RelatonBib
|
|
329
330
|
ret[:series] = array(ret[:series])&.map do |s|
|
330
331
|
s[:formattedref] && s[:formattedref] = formattedref(s[:formattedref])
|
331
332
|
if s[:title]
|
332
|
-
s[:title] = { content: s[:title] } unless s.is_a?(Hash)
|
333
|
+
s[:title] = { content: s[:title] } unless s[:title].is_a?(Hash)
|
333
334
|
s[:title] = typed_title_strig(s[:title])
|
334
335
|
end
|
335
336
|
s[:abbreviation] && s[:abbreviation] = localizedstring(s[:abbreviation])
|
@@ -11,21 +11,35 @@ module RelatonBib
|
|
11
11
|
# @return [Array<String>] script Iso15924 code
|
12
12
|
attr_reader :script
|
13
13
|
|
14
|
-
# @return [String]
|
14
|
+
# @return [String, Array<RelatonBib::LocalizedString>]
|
15
15
|
attr_accessor :content
|
16
16
|
|
17
|
-
# @param content [String]
|
17
|
+
# @param content [String, Array<RelatonBib::LocalizedString>]
|
18
18
|
# @param language [String] language code Iso639
|
19
19
|
# @param script [String] script code Iso15924
|
20
20
|
def initialize(content, language = nil, script = nil)
|
21
|
+
unless content.is_a?(String) || content.is_a?(Array) &&
|
22
|
+
(inv = content.reject { |c| c.is_a?(LocalizedString) || c.is_a?(Hash) }).
|
23
|
+
none? && content.any?
|
24
|
+
klass = content.is_a?(Array) ? inv.first.class : content.class
|
25
|
+
raise ArgumentError, "invalid LocalizedString content type: #{klass}"
|
26
|
+
end
|
21
27
|
@language = language.is_a?(String) ? [language] : language
|
22
28
|
@script = script.is_a?(String) ? [script] : script
|
23
|
-
@content = content
|
29
|
+
@content = if content.is_a?(Array)
|
30
|
+
content.map do |c|
|
31
|
+
if c.is_a?(Hash)
|
32
|
+
LocalizedString.new c[:content], c[:language], c[:script]
|
33
|
+
else c
|
34
|
+
end
|
35
|
+
end
|
36
|
+
else content
|
37
|
+
end
|
24
38
|
end
|
25
39
|
|
26
40
|
# @return [String]
|
27
41
|
def to_s
|
28
|
-
content
|
42
|
+
content.is_a?(String) ? content : content.first.to_s
|
29
43
|
end
|
30
44
|
|
31
45
|
# @return [TrueClass, FalseClass]
|
@@ -37,19 +51,26 @@ module RelatonBib
|
|
37
51
|
def to_xml(builder)
|
38
52
|
return unless content
|
39
53
|
|
40
|
-
|
41
|
-
|
42
|
-
|
54
|
+
if content.is_a?(Array)
|
55
|
+
content.each { |c| builder.variant { c.to_xml builder } }
|
56
|
+
else
|
57
|
+
builder.parent["language"] = language.join(",") if language&.any?
|
58
|
+
builder.parent["script"] = script.join(",") if script&.any?
|
59
|
+
builder.text content.encode(xml: :text)
|
60
|
+
end
|
43
61
|
end
|
44
62
|
|
45
63
|
# @return [Hash]
|
46
64
|
def to_hash
|
47
|
-
|
65
|
+
if content.is_a? String
|
66
|
+
return content unless language || script
|
48
67
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
68
|
+
hash = { "content" => content }
|
69
|
+
hash["language"] = single_element_array(language) if language&.any?
|
70
|
+
hash["script"] = single_element_array(script) if script&.any?
|
71
|
+
hash
|
72
|
+
else content.map &:to_hash
|
73
|
+
end
|
53
74
|
end
|
54
75
|
end
|
55
76
|
end
|
data/lib/relaton_bib/version.rb
CHANGED
@@ -159,8 +159,12 @@ module RelatonBib
|
|
159
159
|
def ttitle(title)
|
160
160
|
return unless title
|
161
161
|
|
162
|
+
variants = title.xpath("variant").map do |v|
|
163
|
+
LocalizedString.new v.text, v[:language], v[:script]
|
164
|
+
end
|
165
|
+
content = variants.any? ? variants : title.text
|
162
166
|
TypedTitleString.new(
|
163
|
-
type: title[:type], content:
|
167
|
+
type: title[:type], content: content, language: title[:language],
|
164
168
|
script: title[:script], format: title[:format]
|
165
169
|
)
|
166
170
|
end
|
data/relaton-bib.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
lib = File.expand_path("
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
require "relaton_bib/version"
|
4
4
|
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
|
16
16
|
# Specify which files should be added to the gem when it is released.
|
17
17
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
-
spec.files = Dir.chdir(File.expand_path(
|
18
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
19
19
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
20
|
end
|
21
21
|
spec.bindir = "exe"
|
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.require_paths = ["lib"]
|
24
24
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
25
25
|
|
26
|
+
spec.add_development_dependency "byebug"
|
26
27
|
spec.add_development_dependency "debase"
|
27
28
|
spec.add_development_dependency "equivalent-xml", "~> 0.6"
|
28
29
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -30,7 +31,6 @@ Gem::Specification.new do |spec|
|
|
30
31
|
spec.add_development_dependency "ruby-debug-ide"
|
31
32
|
spec.add_development_dependency "ruby-jing"
|
32
33
|
spec.add_development_dependency "simplecov"
|
33
|
-
spec.add_development_dependency "byebug"
|
34
34
|
|
35
35
|
spec.add_dependency "addressable"
|
36
36
|
spec.add_dependency "bibtex-ruby"
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton-bib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.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: 2020-05-
|
11
|
+
date: 2020-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: byebug
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: debase
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,20 +122,6 @@ dependencies:
|
|
108
122
|
- - ">="
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: byebug
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: addressable
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|