relaton-bib 0.3.4 → 0.3.9
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/.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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c135f7e0e77b7cfa7c31ae9743e0c6bf716a27e0
|
4
|
+
data.tar.gz: 4998ac95553d5ab1e6248b48e7c41e36179c49c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 290f43263f27e6a5f66e091d89bb95e296470311994525359dfd7f8dc63c11e329b404a6a56f8f834666e78f7a6aea6d7b5c05e3b4563f225454cad119ec7f33
|
7
|
+
data.tar.gz: 40f1bb2b469029b5cfa334207bd1d230deb49b4eae361dec3ef221f2efe3714e91e22c1d0706c8f6e43f14343907b9b6d08be6e75959b2c10d483234d182cf11
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Auto-generated !!! Do not edit it manually
|
2
|
+
# use ci-master https://github.com/metanorma/metanorma-build-scripts
|
3
|
+
name: macos
|
4
|
+
|
5
|
+
on: [push]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
test-macos:
|
9
|
+
name: Test on Ruby ${{ matrix.ruby }} macOS
|
10
|
+
runs-on: macos-latest
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
ruby: [ '2.6', '2.5', '2.4' ]
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@master
|
16
|
+
- name: Use Ruby
|
17
|
+
uses: actions/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: ${{ matrix.ruby }}
|
20
|
+
architecture: 'x64'
|
21
|
+
- name: Update gems
|
22
|
+
run: |
|
23
|
+
sudo gem install bundler -v "~> 2" --force
|
24
|
+
bundle install --jobs 4 --retry 3
|
25
|
+
- name: Run specs
|
26
|
+
run: |
|
27
|
+
bundle exec rake
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Auto-generated !!! Do not edit it manually
|
2
|
+
# use ci-master https://github.com/metanorma/metanorma-build-scripts
|
3
|
+
name: ubuntu
|
4
|
+
|
5
|
+
on: [push]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
test-linux:
|
9
|
+
name: Test on Ruby ${{ matrix.ruby }} Ubuntu
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
ruby: [ '2.6', '2.5', '2.4' ]
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@master
|
16
|
+
- name: Use Ruby
|
17
|
+
uses: actions/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: ${{ matrix.ruby }}
|
20
|
+
architecture: 'x64'
|
21
|
+
- name: Update gems
|
22
|
+
run: |
|
23
|
+
gem install bundler -v "~> 2"
|
24
|
+
bundle install --jobs 4 --retry 3
|
25
|
+
- name: Run specs
|
26
|
+
run: |
|
27
|
+
bundle exec rake
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Auto-generated !!! Do not edit it manually
|
2
|
+
# use ci-master https://github.com/metanorma/metanorma-build-scripts
|
3
|
+
name: windows
|
4
|
+
|
5
|
+
on: [push]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
test-windows:
|
9
|
+
name: Test on Ruby ${{ matrix.ruby }} Windows
|
10
|
+
runs-on: windows-latest
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
ruby: [ '2.6', '2.5', '2.4' ]
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@master
|
16
|
+
- name: Use Ruby
|
17
|
+
uses: actions/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: ${{ matrix.ruby }}
|
20
|
+
architecture: 'x64'
|
21
|
+
- name: Update gems
|
22
|
+
shell: pwsh
|
23
|
+
run: |
|
24
|
+
gem install bundler -v "~> 2"
|
25
|
+
bundle config --local path vendor/bundle
|
26
|
+
bundle update
|
27
|
+
bundle install --jobs 4 --retry 3
|
28
|
+
- name: Run specs
|
29
|
+
run: |
|
30
|
+
bundle exec rake
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
relaton-bib (0.3.
|
4
|
+
relaton-bib (0.3.9)
|
5
5
|
addressable
|
6
|
-
nokogiri
|
6
|
+
nokogiri
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
addressable (2.
|
12
|
-
public_suffix (>= 2.0.2, <
|
11
|
+
addressable (2.7.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
13
13
|
byebug (11.0.1)
|
14
14
|
debase (0.2.3)
|
15
15
|
debase-ruby_core_source (>= 0.10.2)
|
@@ -22,7 +22,7 @@ GEM
|
|
22
22
|
mini_portile2 (2.4.0)
|
23
23
|
nokogiri (1.10.3)
|
24
24
|
mini_portile2 (~> 2.4.0)
|
25
|
-
public_suffix (
|
25
|
+
public_suffix (4.0.1)
|
26
26
|
rake (10.5.0)
|
27
27
|
rspec (3.8.0)
|
28
28
|
rspec-core (~> 3.8.0)
|
data/lib/relaton_bib.rb
CHANGED
@@ -1,8 +1,40 @@
|
|
1
1
|
require "relaton_bib/version"
|
2
|
-
require "relaton_bib/bibliographic_item
|
2
|
+
require "relaton_bib/bibliographic_item"
|
3
|
+
require "relaton_bib/hit_collection"
|
4
|
+
require "relaton_bib/hit"
|
3
5
|
|
4
6
|
module RelatonBib
|
5
7
|
class Error < StandardError; end
|
6
8
|
|
7
9
|
class RequestError < StandardError; end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
# @param date [String]
|
13
|
+
# @return [Date, NilClass]
|
14
|
+
def parse_date(sdate)
|
15
|
+
if /(?<date>\w+\s\d{4})/ =~ sdate # February 2012
|
16
|
+
Date.strptime(date, "%B %Y")
|
17
|
+
elsif /(?<date>\w+\s\d{1,2},\s\d{4})/ =~ sdate # February 11, 2012
|
18
|
+
Date.strptime(date, "%B %d, %Y")
|
19
|
+
elsif /(?<date>\d{4}-\d{2}-\d{2})/ =~ sdate # 2012-02-11
|
20
|
+
Date.parse(date)
|
21
|
+
elsif /(?<date>\d{4}-\d{2})/ =~ sdate # 2012-02
|
22
|
+
Date.strptime date, "%Y-%m"
|
23
|
+
elsif /(?<date>\d{4})/ =~ sdate # 2012
|
24
|
+
Date.strptime date, "%Y"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
# @param array [Array]
|
32
|
+
# @return [Array<String>, String]
|
33
|
+
def single_element_array(array)
|
34
|
+
if array.size > 1
|
35
|
+
array.map { |e| e.is_a?(String) ? e : e.to_hash }
|
36
|
+
else
|
37
|
+
array[0].is_a?(String) ? array[0] : array[0].to_hash
|
38
|
+
end
|
39
|
+
end
|
8
40
|
end
|
@@ -45,9 +45,9 @@ module RelatonBib
|
|
45
45
|
|
46
46
|
# @return [Hash]
|
47
47
|
def to_hash
|
48
|
-
hash = { type
|
49
|
-
hash[
|
48
|
+
hash = { "type" => type, "reference_from" => reference_from }
|
49
|
+
hash["reference_to"] = reference_to if reference_to
|
50
50
|
hash
|
51
51
|
end
|
52
52
|
end
|
53
|
-
end
|
53
|
+
end
|
@@ -2,6 +2,8 @@ module RelatonBib
|
|
2
2
|
# Version
|
3
3
|
class BibliographicItem
|
4
4
|
class Version
|
5
|
+
include RelatonBib
|
6
|
+
|
5
7
|
# @return [String, NilClass]
|
6
8
|
attr_reader :revision_date
|
7
9
|
|
@@ -18,7 +20,7 @@ module RelatonBib
|
|
18
20
|
# @param builder [Nokogiri::XML::Builder]
|
19
21
|
def to_xml(builder)
|
20
22
|
builder.version do
|
21
|
-
builder.
|
23
|
+
builder.send("revision-date", revision_date) if revision_date
|
22
24
|
draft.each { |d| builder.draft d }
|
23
25
|
end
|
24
26
|
end
|
@@ -26,8 +28,8 @@ module RelatonBib
|
|
26
28
|
# @return [Hash]
|
27
29
|
def to_hash
|
28
30
|
hash = {}
|
29
|
-
hash[
|
30
|
-
hash[
|
31
|
+
hash["revision_date"] = revision_date if revision_date
|
32
|
+
hash["draft"] = single_element_array(draft) if draft&.any?
|
31
33
|
hash
|
32
34
|
end
|
33
35
|
end
|
@@ -6,8 +6,7 @@ module RelatonBib
|
|
6
6
|
# Bibliographic date.
|
7
7
|
class BibliographicDate
|
8
8
|
TYPES = %w[published accessed created implemented obsoleted confirmed
|
9
|
-
updated issued transmitted copied unchanged circulated
|
10
|
-
].freeze
|
9
|
+
updated issued transmitted copied unchanged circulated adapted].freeze
|
11
10
|
|
12
11
|
# @return [String]
|
13
12
|
attr_reader :type
|
@@ -22,18 +21,18 @@ module RelatonBib
|
|
22
21
|
attr_reader :on
|
23
22
|
|
24
23
|
# @param type [String] "published", "accessed", "created", "activated"
|
24
|
+
# @param on [String]
|
25
25
|
# @param from [String]
|
26
26
|
# @param to [String]
|
27
27
|
def initialize(type:, on: nil, from: nil, to: nil)
|
28
28
|
raise ArgumentError, "expected :on or :from argument" unless on || from
|
29
29
|
|
30
|
-
TYPES.include?
|
31
|
-
raise ArgumentError, %{Type "#{type}" is invalid.} unless
|
30
|
+
# raise ArgumentError, "invalid type: #{type}" unless TYPES.include? type
|
32
31
|
|
33
32
|
@type = type
|
34
|
-
@on = parse_date on
|
35
|
-
@from = parse_date from
|
36
|
-
@to = parse_date to
|
33
|
+
@on = RelatonBib.parse_date on
|
34
|
+
@from = RelatonBib.parse_date from
|
35
|
+
@to = RelatonBib.parse_date to
|
37
36
|
end
|
38
37
|
|
39
38
|
# rubocop:disable Metrics/AbcSize
|
@@ -54,10 +53,10 @@ module RelatonBib
|
|
54
53
|
|
55
54
|
# @return [Hash]
|
56
55
|
def to_hash
|
57
|
-
hash = { type
|
58
|
-
hash[
|
59
|
-
hash[
|
60
|
-
hash[
|
56
|
+
hash = { "type" => type }
|
57
|
+
hash["value"] = on.to_s if on
|
58
|
+
hash["from"] = from.to_s if from
|
59
|
+
hash["to"] = to.to_s if to
|
61
60
|
hash
|
62
61
|
end
|
63
62
|
|
@@ -74,19 +73,5 @@ module RelatonBib
|
|
74
73
|
else date.year
|
75
74
|
end
|
76
75
|
end
|
77
|
-
|
78
|
-
# @params date [String] 'yyyy', 'yyyy-mm', 'yyyy-mm-dd
|
79
|
-
# @return [Date]
|
80
|
-
def parse_date(date)
|
81
|
-
return unless date
|
82
|
-
|
83
|
-
if date =~ /^\d{4}$/
|
84
|
-
Date.strptime date, "%Y"
|
85
|
-
elsif date =~ /^\d{4}-\d{2}$/
|
86
|
-
Date.strptime date, "%Y-%m"
|
87
|
-
elsif date =~ /\d{4}-\d{2}-\d{2}$/
|
88
|
-
Date.strptime date, "%Y-%m-%d"
|
89
|
-
end
|
90
|
-
end
|
91
76
|
end
|
92
77
|
end
|
@@ -26,11 +26,12 @@ require "relaton_bib/hash_converter"
|
|
26
26
|
module RelatonBib
|
27
27
|
# Bibliographic item
|
28
28
|
class BibliographicItem
|
29
|
+
include RelatonBib
|
30
|
+
|
29
31
|
TYPES = %W[article book booklet conference manual proceedings presentation
|
30
32
|
thesis techreport standard unpublished map electronic\sresource
|
31
33
|
audiovisual film video broadcast graphic_work music patent
|
32
|
-
inbook incollection inproceedings journal
|
33
|
-
].freeze
|
34
|
+
inbook incollection inproceedings journal].freeze
|
34
35
|
|
35
36
|
# @return [String, NilClass]
|
36
37
|
attr_reader :id
|
@@ -168,7 +169,7 @@ module RelatonBib
|
|
168
169
|
# @option link [String] :content
|
169
170
|
def initialize(**args)
|
170
171
|
if args[:type] && !TYPES.include?(args[:type])
|
171
|
-
|
172
|
+
warn %{Document type "#{args[:type]}" is invalid.}
|
172
173
|
end
|
173
174
|
|
174
175
|
@title = (args[:title] || []).map do |t|
|
@@ -209,7 +210,7 @@ module RelatonBib
|
|
209
210
|
@language = args.fetch :language, []
|
210
211
|
@script = args.fetch :script, []
|
211
212
|
@status = args[:docstatus]
|
212
|
-
@relation
|
213
|
+
@relation = DocRelationCollection.new(args[:relation] || [])
|
213
214
|
@link = args.fetch(:link, []).map { |s| s.is_a?(Hash) ? TypedUri.new(s) : s }
|
214
215
|
@series = args.fetch :series, []
|
215
216
|
@medium = args[:medium]
|
@@ -273,32 +274,32 @@ module RelatonBib
|
|
273
274
|
# @return [Hash]
|
274
275
|
def to_hash
|
275
276
|
hash = {}
|
276
|
-
hash[
|
277
|
-
hash[
|
278
|
-
hash[
|
279
|
-
hash[
|
280
|
-
hash[
|
281
|
-
hash[
|
282
|
-
hash[
|
283
|
-
hash[
|
284
|
-
hash[
|
285
|
-
hash[
|
286
|
-
hash[
|
287
|
-
hash[
|
288
|
-
hash[
|
289
|
-
hash[
|
290
|
-
hash[
|
291
|
-
hash[
|
292
|
-
hash[
|
293
|
-
hash[
|
294
|
-
hash[
|
295
|
-
hash[
|
296
|
-
hash[
|
297
|
-
hash[
|
298
|
-
hash[
|
299
|
-
hash[
|
300
|
-
hash[
|
301
|
-
hash[
|
277
|
+
hash["id"] = id if id
|
278
|
+
hash["title"] = single_element_array(title) if title&.any?
|
279
|
+
hash["link"] = single_element_array(link) if link&.any?
|
280
|
+
hash["type"] = type if type
|
281
|
+
hash["docid"] = single_element_array(docidentifier) if docidentifier&.any?
|
282
|
+
hash["docnumber"] = docnumber if docnumber
|
283
|
+
hash["date"] = single_element_array(date) if date&.any?
|
284
|
+
hash["contributor"] = single_element_array(contributor) if contributor&.any?
|
285
|
+
hash["edition"] = edition if edition
|
286
|
+
hash["version"] = version.to_hash if version
|
287
|
+
hash["biblionote"] = single_element_array(biblionote) if biblionote&.any?
|
288
|
+
hash["language"] = single_element_array(language) if language&.any?
|
289
|
+
hash["script"] = single_element_array(script) if script&.any?
|
290
|
+
hash["formattedref"] = formattedref.to_hash if formattedref
|
291
|
+
hash["abstract"] = single_element_array(abstract) if abstract&.any?
|
292
|
+
hash["docstatus"] = status.to_hash if status
|
293
|
+
hash["copyright"] = copyright.to_hash if copyright
|
294
|
+
hash["relation"] = single_element_array(relation) if relation&.any?
|
295
|
+
hash["series"] = single_element_array(series) if series&.any?
|
296
|
+
hash["medium"] = medium.to_hash if medium
|
297
|
+
hash["place"] = single_element_array(place) if place&.any?
|
298
|
+
hash["extent"] = single_element_array(extent) if extent&.any?
|
299
|
+
hash["accesslocation"] = single_element_array(accesslocation) if accesslocation&.any?
|
300
|
+
hash["classification"] = classification.to_hash if classification
|
301
|
+
hash["validity"] = validity.to_hash if validity
|
302
|
+
hash["fetched"] = fetched.to_s if fetched
|
302
303
|
hash
|
303
304
|
end
|
304
305
|
|
@@ -4,17 +4,17 @@ require "relaton_bib/person"
|
|
4
4
|
|
5
5
|
# RelatonBib module
|
6
6
|
module RelatonBib
|
7
|
-
|
8
7
|
# Contributor's role.
|
9
8
|
class ContributorRole
|
9
|
+
include RelatonBib
|
10
|
+
|
10
11
|
TYPES = %w[author performer publisher editor adapter translator
|
11
|
-
distributor
|
12
|
-
].freeze
|
12
|
+
distributor].freeze
|
13
13
|
|
14
14
|
# @return [Array<RelatonBib::FormattedString>]
|
15
15
|
attr_reader :description
|
16
16
|
|
17
|
-
# @return [
|
17
|
+
# @return [Strig]
|
18
18
|
attr_reader :type
|
19
19
|
|
20
20
|
# @param type [String] allowed types "author", "editor",
|
@@ -29,6 +29,7 @@ module RelatonBib
|
|
29
29
|
@description = args.fetch(:description, []).map { |d| FormattedString.new content: d, format: nil }
|
30
30
|
end
|
31
31
|
|
32
|
+
# @param builder [Nokogiri::XML::Builder]
|
32
33
|
def to_xml(builder)
|
33
34
|
builder.role(type: type) do
|
34
35
|
description.each do |d|
|
@@ -37,18 +38,22 @@ module RelatonBib
|
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
|
-
# @return [
|
41
|
+
# @return [Hash, String]
|
41
42
|
def to_hash
|
42
43
|
if description&.any?
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
hash = { "description" => single_element_array(description) }
|
45
|
+
hash["type"] = type if type
|
46
|
+
hash
|
47
|
+
elsif type
|
48
|
+
type
|
46
49
|
end
|
47
50
|
end
|
48
51
|
end
|
49
52
|
|
50
53
|
# Contribution info.
|
51
54
|
class ContributionInfo
|
55
|
+
include RelatonBib
|
56
|
+
|
52
57
|
# @return [Array<RelatonBib::ContributorRole>]
|
53
58
|
attr_reader :role
|
54
59
|
|
@@ -71,7 +76,7 @@ module RelatonBib
|
|
71
76
|
# @return [Hash]
|
72
77
|
def to_hash
|
73
78
|
hash = entity.to_hash
|
74
|
-
hash[
|
79
|
+
hash["role"] = single_element_array(role) if role&.any?
|
75
80
|
hash
|
76
81
|
end
|
77
82
|
end
|