relaton-bib 0.3.4 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/macos.yml +27 -0
- data/.github/workflows/ubuntu.yml +27 -0
- data/.github/workflows/windows.yml +30 -0
- data/Gemfile.lock +5 -5
- data/lib/relaton_bib.rb +33 -1
- data/lib/relaton_bib/bib_item_locality.rb +3 -3
- data/lib/relaton_bib/biblio_note.rb +4 -1
- data/lib/relaton_bib/biblio_version.rb +5 -3
- data/lib/relaton_bib/bibliographic_date.rb +10 -25
- data/lib/relaton_bib/bibliographic_item.rb +31 -30
- data/lib/relaton_bib/classification.rb +2 -2
- data/lib/relaton_bib/contribution_info.rb +14 -9
- data/lib/relaton_bib/contributor.rb +14 -10
- data/lib/relaton_bib/copyright_association.rb +5 -5
- data/lib/relaton_bib/document_identifier.rb +2 -2
- data/lib/relaton_bib/document_relation.rb +4 -2
- data/lib/relaton_bib/document_status.rb +3 -3
- data/lib/relaton_bib/formatted_string.rb +6 -3
- data/lib/relaton_bib/hash_converter.rb +143 -98
- data/lib/relaton_bib/hit.rb +32 -0
- data/lib/relaton_bib/hit_collection.rb +34 -0
- data/lib/relaton_bib/localized_string.rb +7 -3
- data/lib/relaton_bib/medium.rb +3 -3
- data/lib/relaton_bib/organization.rb +25 -29
- data/lib/relaton_bib/person.rb +13 -20
- data/lib/relaton_bib/series.rb +10 -10
- data/lib/relaton_bib/typed_title_string.rb +10 -3
- data/lib/relaton_bib/typed_uri.rb +2 -2
- data/lib/relaton_bib/validity.rb +3 -3
- data/lib/relaton_bib/version.rb +1 -1
- data/lib/relaton_bib/xml_parser.rb +17 -6
- data/relaton-bib.gemspec +2 -2
- metadata +12 -9
- data/.travis.yml +0 -18
- data/appveyor.yml +0 -37
@@ -0,0 +1,32 @@
|
|
1
|
+
module RelatonBib
|
2
|
+
class Hit
|
3
|
+
# @return [Array<Hash>]
|
4
|
+
attr_reader :hit
|
5
|
+
|
6
|
+
# @param hit [Hash]
|
7
|
+
# @param hit_collection [RelatonIso::HitCollection, RelatonNist:HitCollection]
|
8
|
+
def initialize(hit, hit_collection = nil)
|
9
|
+
@hit = hit
|
10
|
+
@hit_collection = hit_collection
|
11
|
+
end
|
12
|
+
|
13
|
+
# @return [String]
|
14
|
+
def to_s
|
15
|
+
inspect
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [String]
|
19
|
+
def inspect
|
20
|
+
"<#{self.class}:#{format('%#.14x', object_id << 1)} "\
|
21
|
+
"@text=\"#{@hit_collection&.text}\" "\
|
22
|
+
"@fetched=\"#{!@fetch.nil?}\" "\
|
23
|
+
"@fullIdentifier=\"#{@fetch&.shortref(nil)}\" "\
|
24
|
+
"@title=\"#{@hit[:code]}\">"
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [String]
|
28
|
+
def to_xml(**opts)
|
29
|
+
fetch.to_xml **opts
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module RelatonBib
|
2
|
+
class HitCollection < Array
|
3
|
+
# @return [TrueClass, FalseClass]
|
4
|
+
attr_reader :fetched
|
5
|
+
|
6
|
+
# @return [String]
|
7
|
+
attr_reader :text
|
8
|
+
|
9
|
+
# @return [String]
|
10
|
+
attr_reader :year
|
11
|
+
|
12
|
+
# @return [RelatonIso::HitCollection]
|
13
|
+
def fetch
|
14
|
+
workers = WorkersPool.new 4
|
15
|
+
workers.worker(&:fetch)
|
16
|
+
each do |hit|
|
17
|
+
workers << hit
|
18
|
+
end
|
19
|
+
workers.end
|
20
|
+
workers.result
|
21
|
+
@fetched = true
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
inspect
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [String]
|
30
|
+
def inspect
|
31
|
+
"<#{self.class}:#{format('%#.14x', object_id << 1)} @fetched=#{@fetched}>"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -3,6 +3,8 @@
|
|
3
3
|
module RelatonBib
|
4
4
|
# Localized string.
|
5
5
|
class LocalizedString
|
6
|
+
include RelatonBib
|
7
|
+
|
6
8
|
# @return [Array<String>] language Iso639 code
|
7
9
|
attr_reader :language
|
8
10
|
|
@@ -42,9 +44,11 @@ module RelatonBib
|
|
42
44
|
|
43
45
|
# @return [Hash]
|
44
46
|
def to_hash
|
45
|
-
|
46
|
-
|
47
|
-
hash
|
47
|
+
return content unless language || script
|
48
|
+
|
49
|
+
hash = { "content" => content }
|
50
|
+
hash["language"] = single_element_array(language) if language&.any?
|
51
|
+
hash["script"] = single_element_array(script) if script&.any?
|
48
52
|
hash
|
49
53
|
end
|
50
54
|
end
|
data/lib/relaton_bib/medium.rb
CHANGED
@@ -24,9 +24,9 @@ module RelatonBib
|
|
24
24
|
# @return [Hash]
|
25
25
|
def to_hash
|
26
26
|
hash = {}
|
27
|
-
hash[
|
28
|
-
hash[
|
29
|
-
hash[
|
27
|
+
hash["form"] = form if form
|
28
|
+
hash["size"] = size if size
|
29
|
+
hash["scale"] = scale if scale
|
30
30
|
hash
|
31
31
|
end
|
32
32
|
end
|
@@ -37,7 +37,7 @@ module RelatonBib
|
|
37
37
|
|
38
38
|
# @return [Hash]
|
39
39
|
def to_hash
|
40
|
-
{ type
|
40
|
+
{ "type" => type, "id" => value }
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -55,15 +55,9 @@ module RelatonBib
|
|
55
55
|
# @return [Array<RelatonBib::OrgIdentifier>]
|
56
56
|
attr_reader :identifier
|
57
57
|
|
58
|
-
def hash2locstr(name)
|
59
|
-
name.is_a?(Hash) ?
|
60
|
-
LocalizedString.new(name[:content], name[:language], name[:script]) :
|
61
|
-
LocalizedString.new(name)
|
62
|
-
end
|
63
|
-
|
64
58
|
# @param name [String, Hash, Array<String, Hash>]
|
65
|
-
# @param abbreviation [RelatoBib::
|
66
|
-
# @param subdivision [RelatoBib::
|
59
|
+
# @param abbreviation [RelatoBib::LocalizedString, String]
|
60
|
+
# @param subdivision [RelatoBib::LocalizedString, String]
|
67
61
|
# @param url [String]
|
68
62
|
# @param identifier [Array<RelatonBib::OrgIdentifier>]
|
69
63
|
# @param contact [Array<RelatonBib::Address, RelatonBib::Contact>]
|
@@ -73,24 +67,14 @@ module RelatonBib
|
|
73
67
|
super(url: args[:url], contact: args.fetch(:contact, []))
|
74
68
|
|
75
69
|
@name = if args[:name].is_a?(Array)
|
76
|
-
args[:name].map { |n|
|
70
|
+
args[:name].map { |n| localized_string(n) }
|
77
71
|
else
|
78
|
-
[
|
72
|
+
[localized_string(args[:name])]
|
79
73
|
end
|
80
74
|
|
81
|
-
@abbreviation =
|
82
|
-
|
83
|
-
|
84
|
-
args[:abbreviation]
|
85
|
-
end
|
86
|
-
|
87
|
-
@subdivision = if args[:subdivision].is_a?(String)
|
88
|
-
LocalizedString.new(args[:subdivision])
|
89
|
-
else
|
90
|
-
args[:subdivision]
|
91
|
-
end
|
92
|
-
|
93
|
-
@identifier = args.fetch(:identifier, [])
|
75
|
+
@abbreviation = localized_string args[:abbreviation]
|
76
|
+
@subdivision = localized_string args[:subdivision]
|
77
|
+
@identifier = args.fetch(:identifier, [])
|
94
78
|
end
|
95
79
|
|
96
80
|
# @param builder [Nokogiri::XML::Builder]
|
@@ -109,11 +93,23 @@ module RelatonBib
|
|
109
93
|
|
110
94
|
# @return [Hash]
|
111
95
|
def to_hash
|
112
|
-
hash = { name
|
113
|
-
hash[
|
114
|
-
hash[
|
115
|
-
hash[
|
116
|
-
{ organization
|
96
|
+
hash = { "name" => single_element_array(name) }
|
97
|
+
hash["abbreviation"] = abbreviation.to_hash if abbreviation
|
98
|
+
hash["identifier"] = single_element_array(identifier) if identifier&.any?
|
99
|
+
hash["subdivision"] = subdivision.to_hash if subdivision
|
100
|
+
{ "organization" => hash.merge(super) }
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
# @param arg [String, Hash, RelatoBib::LocalizedString]
|
106
|
+
# @return [RelatoBib::LocalizedString]
|
107
|
+
def localized_string(arg)
|
108
|
+
if arg.is_a?(String) then LocalizedString.new(arg)
|
109
|
+
elsif arg.is_a?(Hash)
|
110
|
+
LocalizedString.new(arg[:content], arg[:language], arg[:script])
|
111
|
+
elsif arg.is_a? LocalizedString then arg
|
112
|
+
end
|
117
113
|
end
|
118
114
|
end
|
119
115
|
end
|
data/lib/relaton_bib/person.rb
CHANGED
@@ -5,6 +5,8 @@ require "relaton_bib/contributor"
|
|
5
5
|
module RelatonBib
|
6
6
|
# Person's full name
|
7
7
|
class FullName
|
8
|
+
include RelatonBib
|
9
|
+
|
8
10
|
# @return [Array<RelatonBib::LocalizedString>]
|
9
11
|
attr_accessor :forename
|
10
12
|
|
@@ -60,22 +62,13 @@ module RelatonBib
|
|
60
62
|
# @return [Hash]
|
61
63
|
def to_hash
|
62
64
|
hash = {}
|
63
|
-
hash[
|
64
|
-
hash[
|
65
|
-
hash[
|
66
|
-
hash[
|
67
|
-
hash[
|
68
|
-
hash[
|
65
|
+
hash["forename"] = single_element_array(forename) if forename&.any?
|
66
|
+
hash["initial"] = single_element_array(initial) if initial&.any?
|
67
|
+
hash["surname"] = surname.to_hash if surname
|
68
|
+
hash["addition"] = single_element_array(addition) if addition&.any?
|
69
|
+
hash["prefix"] = single_element_array(prefix) if prefix&.any?
|
70
|
+
hash["completename"] = completename.to_hash if completename
|
69
71
|
hash
|
70
|
-
# instance_variables.reduce({}) do |hash, var|
|
71
|
-
# val = instance_variable_get var
|
72
|
-
# if val || val.is_a?(Array) && val.any?
|
73
|
-
# key = var.to_s.sub("@", "").to_sym
|
74
|
-
# hash.merge key => val
|
75
|
-
# else
|
76
|
-
# hash
|
77
|
-
# end
|
78
|
-
# end
|
79
72
|
end
|
80
73
|
end
|
81
74
|
|
@@ -118,7 +111,7 @@ module RelatonBib
|
|
118
111
|
|
119
112
|
# @return [Hash]
|
120
113
|
def to_hash
|
121
|
-
{ type
|
114
|
+
{ "type" => type, "id" => value }
|
122
115
|
end
|
123
116
|
end
|
124
117
|
|
@@ -156,10 +149,10 @@ module RelatonBib
|
|
156
149
|
|
157
150
|
# @return [Hash]
|
158
151
|
def to_hash
|
159
|
-
hash = { name
|
160
|
-
hash[
|
161
|
-
hash[
|
162
|
-
{ person
|
152
|
+
hash = { "name" => name.to_hash }
|
153
|
+
hash["affiliation"] = single_element_array(affiliation) if affiliation&.any?
|
154
|
+
hash["identifier"] = single_element_array(identifier) if identifier&.any?
|
155
|
+
{ "person" => hash.merge(super) }
|
163
156
|
end
|
164
157
|
end
|
165
158
|
end
|
data/lib/relaton_bib/series.rb
CHANGED
@@ -97,16 +97,16 @@ module RelatonBib
|
|
97
97
|
# @return [Hash]
|
98
98
|
def to_hash
|
99
99
|
hash = {}
|
100
|
-
hash[
|
101
|
-
hash[
|
102
|
-
hash[
|
103
|
-
hash[
|
104
|
-
hash[
|
105
|
-
hash[
|
106
|
-
hash[
|
107
|
-
hash[
|
108
|
-
hash[
|
109
|
-
hash[
|
100
|
+
hash["type"] = type if type
|
101
|
+
hash["formattedref"] = formattedref.to_hash if formattedref
|
102
|
+
hash["title"] = title.to_hash if title
|
103
|
+
hash["place"] = place if place
|
104
|
+
hash["organization"] = organization if organization
|
105
|
+
hash["abbreviation"] = abbreviation.to_hash if abbreviation
|
106
|
+
hash["from"] = from if from
|
107
|
+
hash["to"] = to if to
|
108
|
+
hash["number"] = number if number
|
109
|
+
hash["partnumber"] = partnumber if partnumber
|
110
110
|
hash
|
111
111
|
end
|
112
112
|
end
|
@@ -45,9 +45,16 @@ module RelatonBib
|
|
45
45
|
|
46
46
|
# @return [Hash]
|
47
47
|
def to_hash
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
th = title.to_hash
|
49
|
+
return th unless type
|
50
|
+
|
51
|
+
hash = { "type" => type }
|
52
|
+
if th.is_a? String
|
53
|
+
hash["content"] = th
|
54
|
+
else
|
55
|
+
hash.merge! th
|
56
|
+
end
|
57
|
+
hash
|
51
58
|
end
|
52
59
|
end
|
53
60
|
end
|
@@ -6,7 +6,7 @@ module RelatonBib
|
|
6
6
|
# @return [Symbol] :src/:obp/:rss
|
7
7
|
attr_reader :type
|
8
8
|
# @retutn [URI]
|
9
|
-
|
9
|
+
attr_accessor :content
|
10
10
|
|
11
11
|
# @param type [String] src/obp/rss
|
12
12
|
# @param content [String]
|
@@ -22,7 +22,7 @@ module RelatonBib
|
|
22
22
|
|
23
23
|
# @return [Hash]
|
24
24
|
def to_hash
|
25
|
-
{ type
|
25
|
+
{ "type" => type, "content" => content.to_s }
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
data/lib/relaton_bib/validity.rb
CHANGED
@@ -32,9 +32,9 @@ module RelatonBib
|
|
32
32
|
# @return [Hash]
|
33
33
|
def to_hash
|
34
34
|
hash = {}
|
35
|
-
hash[
|
36
|
-
hash[
|
37
|
-
hash[
|
35
|
+
hash["begins"] = begins.strftime(FORMAT) if begins
|
36
|
+
hash["ends"] = ends.strftime(FORMAT) if ends
|
37
|
+
hash["revision"] = revision.strftime(FORMAT) if revision
|
38
38
|
hash
|
39
39
|
end
|
40
40
|
end
|
data/lib/relaton_bib/version.rb
CHANGED
@@ -5,7 +5,8 @@ module RelatonBib
|
|
5
5
|
class << self
|
6
6
|
def from_xml(xml)
|
7
7
|
doc = Nokogiri::XML(xml)
|
8
|
-
|
8
|
+
doc.remove_namespaces!
|
9
|
+
bibitem = doc.at "/bibitem|/bibdata"
|
9
10
|
BibliographicItem.new(item_data(bibitem))
|
10
11
|
end
|
11
12
|
|
@@ -29,8 +30,8 @@ module RelatonBib
|
|
29
30
|
edition: bibitem.at("./edition")&.text,
|
30
31
|
version: fetch_version(bibitem),
|
31
32
|
biblionote: fetch_note(bibitem),
|
32
|
-
language: bibitem
|
33
|
-
script: bibitem
|
33
|
+
language: fetch_language(bibitem),
|
34
|
+
script: fetch_script(bibitem),
|
34
35
|
abstract: fetch_abstract(bibitem),
|
35
36
|
docstatus: fetch_status(bibitem),
|
36
37
|
copyright: fetch_copyright(bibitem),
|
@@ -50,7 +51,7 @@ module RelatonBib
|
|
50
51
|
version = item.at "./version"
|
51
52
|
return unless version
|
52
53
|
|
53
|
-
revision_date = version.at("
|
54
|
+
revision_date = version.at("revision-date")&.text
|
54
55
|
draft = version.xpath("draft").map &:text
|
55
56
|
RelatonBib::BibliographicItem::Version.new revision_date, draft
|
56
57
|
end
|
@@ -67,6 +68,14 @@ module RelatonBib
|
|
67
68
|
end
|
68
69
|
end
|
69
70
|
|
71
|
+
def fetch_language(item)
|
72
|
+
item.xpath("./language").reduce([]) { |a, l| l.text.empty? ? a : a << l.text }
|
73
|
+
end
|
74
|
+
|
75
|
+
def fetch_script(item)
|
76
|
+
item.xpath("./script").reduce([]) { |a, s| s.text.empty? ? a : a << s.text }
|
77
|
+
end
|
78
|
+
|
70
79
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
71
80
|
|
72
81
|
def fetch_series(item)
|
@@ -145,8 +154,9 @@ module RelatonBib
|
|
145
154
|
status = item.at("./status")
|
146
155
|
return unless status
|
147
156
|
|
157
|
+
stage = status.at "stage"
|
148
158
|
DocumentStatus.new(
|
149
|
-
stage:
|
159
|
+
stage: stage ? stage.text : status.text,
|
150
160
|
substage: status.at("substage")&.text,
|
151
161
|
iteration: status.at("iteration")&.text,
|
152
162
|
)
|
@@ -154,8 +164,9 @@ module RelatonBib
|
|
154
164
|
|
155
165
|
def fetch_dates(item)
|
156
166
|
item.xpath("./date").map do |d|
|
167
|
+
type = d[:type].to_s.empty? ? "published" : d[:type]
|
157
168
|
RelatonBib::BibliographicDate.new(
|
158
|
-
type:
|
169
|
+
type: type, on: d.at("on")&.text, from: d.at("from")&.text,
|
159
170
|
to: d.at("to")&.text
|
160
171
|
)
|
161
172
|
end
|
data/relaton-bib.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
|
11
11
|
spec.summary = "RelatonBib: Ruby XMLDOC impementation."
|
12
12
|
spec.description = "RelatonBib: Ruby XMLDOC impementation."
|
13
|
-
spec.homepage = "https://github.com/
|
13
|
+
spec.homepage = "https://github.com/relaton/relaton-item"
|
14
14
|
spec.license = "BSD-2-Clause"
|
15
15
|
|
16
16
|
# Specify which files should be added to the gem when it is released.
|
@@ -33,5 +33,5 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.add_development_dependency "byebug"
|
34
34
|
|
35
35
|
spec.add_dependency "addressable"
|
36
|
-
spec.add_dependency "nokogiri"
|
36
|
+
spec.add_dependency "nokogiri"
|
37
37
|
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: 0.3.
|
4
|
+
version: 0.3.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -140,16 +140,16 @@ dependencies:
|
|
140
140
|
name: nokogiri
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- - "
|
143
|
+
- - ">="
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
145
|
+
version: '0'
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- - "
|
150
|
+
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: '
|
152
|
+
version: '0'
|
153
153
|
description: 'RelatonBib: Ruby XMLDOC impementation.'
|
154
154
|
email:
|
155
155
|
- open.source@ribose.com
|
@@ -157,16 +157,17 @@ executables: []
|
|
157
157
|
extensions: []
|
158
158
|
extra_rdoc_files: []
|
159
159
|
files:
|
160
|
+
- ".github/workflows/macos.yml"
|
161
|
+
- ".github/workflows/ubuntu.yml"
|
162
|
+
- ".github/workflows/windows.yml"
|
160
163
|
- ".gitignore"
|
161
164
|
- ".rspec"
|
162
165
|
- ".rubocop.yml"
|
163
|
-
- ".travis.yml"
|
164
166
|
- Gemfile
|
165
167
|
- Gemfile.lock
|
166
168
|
- LICENSE.txt
|
167
169
|
- README.adoc
|
168
170
|
- Rakefile
|
169
|
-
- appveyor.yml
|
170
171
|
- bin/console
|
171
172
|
- bin/setup
|
172
173
|
- docs/hash.adoc
|
@@ -188,6 +189,8 @@ files:
|
|
188
189
|
- lib/relaton_bib/formatted_string.rb
|
189
190
|
- lib/relaton_bib/hash_converter.rb
|
190
191
|
- lib/relaton_bib/hash_to_bib.rb
|
192
|
+
- lib/relaton_bib/hit.rb
|
193
|
+
- lib/relaton_bib/hit_collection.rb
|
191
194
|
- lib/relaton_bib/localized_string.rb
|
192
195
|
- lib/relaton_bib/medium.rb
|
193
196
|
- lib/relaton_bib/organization.rb
|
@@ -200,7 +203,7 @@ files:
|
|
200
203
|
- lib/relaton_bib/workers_pool.rb
|
201
204
|
- lib/relaton_bib/xml_parser.rb
|
202
205
|
- relaton-bib.gemspec
|
203
|
-
homepage: https://github.com/
|
206
|
+
homepage: https://github.com/relaton/relaton-item
|
204
207
|
licenses:
|
205
208
|
- BSD-2-Clause
|
206
209
|
metadata: {}
|