relaton-oasis 1.14.1 → 1.14.2
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_oasis/data_fetcher.rb +4 -1
- data/lib/relaton_oasis/data_parser.rb +2 -1
- data/lib/relaton_oasis/data_parser_utils.rb +1 -0
- data/lib/relaton_oasis/data_part_parser.rb +1 -0
- data/lib/relaton_oasis/index.rb +75 -0
- data/lib/relaton_oasis/version.rb +1 -1
- data/lib/relaton_oasis.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67ec5cf520e0e8dabe8dc405e5d53040a3a6823bcec412f67cd95c905fe4c923
|
4
|
+
data.tar.gz: ce94a5e864fa390d449b8fc094ec630b9a823377786f45c702df795b0ffe46bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fa0cbc681449431941a33ce0ff7e28ba5e0573799aefba355282470f643fa0be74f9b693fe7f08d0e442ec00d382c842fa050250cad6f9dac36a6b4702e38d6
|
7
|
+
data.tar.gz: f598588770ed59a52b9fab3acf9113afca566c66c81d213bb7b36f22514b9047c97192ce9140e7c7881cde8fd9aa03c1ab783c31203faef2e25ab0d7aed21d3a
|
@@ -11,6 +11,7 @@ module RelatonOasis
|
|
11
11
|
@format = format
|
12
12
|
@ext = @format.sub(/^bib|^rfc/, "")
|
13
13
|
@files = []
|
14
|
+
@index = Index.new
|
14
15
|
end
|
15
16
|
|
16
17
|
#
|
@@ -22,7 +23,7 @@ module RelatonOasis
|
|
22
23
|
def self.fetch(output: "data", format: "yaml")
|
23
24
|
t1 = Time.now
|
24
25
|
puts "Started at: #{t1}"
|
25
|
-
FileUtils.mkdir_p output
|
26
|
+
FileUtils.mkdir_p output
|
26
27
|
new(output, format).fetch
|
27
28
|
t2 = Time.now
|
28
29
|
puts "Stopped at: #{t2}"
|
@@ -40,6 +41,7 @@ module RelatonOasis
|
|
40
41
|
save_doc DataParser.new(item).parse
|
41
42
|
fetch_parts item
|
42
43
|
end
|
44
|
+
@index.save
|
43
45
|
end
|
44
46
|
|
45
47
|
#
|
@@ -72,6 +74,7 @@ module RelatonOasis
|
|
72
74
|
warn "File #{file} already exists. Document: #{doc.docnumber}"
|
73
75
|
else
|
74
76
|
@files << file
|
77
|
+
@index[doc] = file
|
75
78
|
end
|
76
79
|
File.write file, c, encoding: "UTF-8"
|
77
80
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
module RelatonOasis
|
2
|
+
# Parser for OASIS document.
|
2
3
|
class DataParser
|
3
4
|
include RelatonOasis::DataParserUtils
|
4
5
|
|
@@ -106,7 +107,7 @@ module RelatonOasis
|
|
106
107
|
end
|
107
108
|
|
108
109
|
#
|
109
|
-
#
|
110
|
+
# Look for "Cite as" references.
|
110
111
|
#
|
111
112
|
# @return [Array<String>] document part references
|
112
113
|
#
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module RelatonOasis
|
2
|
+
# Index of OASIS documents.
|
3
|
+
class Index
|
4
|
+
#
|
5
|
+
# Initialize a new Index
|
6
|
+
#
|
7
|
+
def initialize(file = "index.yaml")
|
8
|
+
@file = file
|
9
|
+
read
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# Read index from file or fetch from GitHub.
|
14
|
+
#
|
15
|
+
# @return [RelatonOasis::Index, nil] index
|
16
|
+
#
|
17
|
+
def self.create_or_fetch
|
18
|
+
file = File.join Dir.home, ".relaton", "oasis", "index.yaml"
|
19
|
+
unless File.exist?(file) && File.ctime(file) > Time.now - 86_400
|
20
|
+
url = "https://raw.githubusercontent.com/relaton/relaton-data-oasis/main/index.yaml"
|
21
|
+
idx = Net::HTTP.get URI url
|
22
|
+
File.write file, idx, encoding: "UTF-8"
|
23
|
+
end
|
24
|
+
new file
|
25
|
+
rescue StandardError => e
|
26
|
+
warn "Failed to fetch index: #{e.message}"
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Put document's record to index.
|
31
|
+
#
|
32
|
+
# @param [RelatonOasis::OasisBibliographicItem] doc document
|
33
|
+
# @param [String] file file name
|
34
|
+
#
|
35
|
+
def []=(doc, file) # rubocop:disable Metrics/AbcSize
|
36
|
+
rec = self[doc.docidentifier[0].id]
|
37
|
+
rec ||= begin
|
38
|
+
@index << { id: doc.docidentifier[0].id }
|
39
|
+
@index.last
|
40
|
+
end
|
41
|
+
rec[:title] = doc.title[0].title.content
|
42
|
+
rec[:file] = file
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Fetch document's record from index.
|
47
|
+
#
|
48
|
+
# @param [String] id document identifier
|
49
|
+
#
|
50
|
+
# @return [Hash] document's record
|
51
|
+
#
|
52
|
+
def [](id)
|
53
|
+
@index.detect { |i| i[:id] == id }
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# Save index to file.
|
58
|
+
#
|
59
|
+
def save
|
60
|
+
File.open @file, "w:UTF-8" do |f|
|
61
|
+
f.puts "---\n"
|
62
|
+
@index.each do |i|
|
63
|
+
f.puts "- id: '#{i[:id]}'\n title: '#{i[:title]}'\n file: '#{i[:file]}'\n"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Read from file or create empty index.
|
70
|
+
#
|
71
|
+
def read
|
72
|
+
@index = File.exist?(@file) ? YAML.load_file(@file, symbolize_names: true) : []
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/relaton_oasis.rb
CHANGED
@@ -11,6 +11,7 @@ require_relative "relaton_oasis/data_fetcher"
|
|
11
11
|
require_relative "relaton_oasis/data_parser_utils"
|
12
12
|
require_relative "relaton_oasis/data_parser"
|
13
13
|
require_relative "relaton_oasis/data_part_parser"
|
14
|
+
require_relative "relaton_oasis/index"
|
14
15
|
|
15
16
|
module RelatonOasis
|
16
17
|
class Error < StandardError; end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton-oasis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.14.
|
4
|
+
version: 1.14.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: equivalent-xml
|
@@ -181,6 +181,7 @@ files:
|
|
181
181
|
- lib/relaton_oasis/data_parser_utils.rb
|
182
182
|
- lib/relaton_oasis/data_part_parser.rb
|
183
183
|
- lib/relaton_oasis/hash_converter.rb
|
184
|
+
- lib/relaton_oasis/index.rb
|
184
185
|
- lib/relaton_oasis/oasis_bibliographic_item.rb
|
185
186
|
- lib/relaton_oasis/oasis_bibliography.rb
|
186
187
|
- lib/relaton_oasis/processor.rb
|