relaton-oasis 1.14.0 → 1.14.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 160d1fcfcd5ad8d8cacfa535f470fd846e9c2f2bab9db2bf800e31ccaec41663
4
- data.tar.gz: 81efa9566002a45bad7e02b39ca2b7521f20927e2872f23233eb0e183f3c0630
3
+ metadata.gz: 67ec5cf520e0e8dabe8dc405e5d53040a3a6823bcec412f67cd95c905fe4c923
4
+ data.tar.gz: ce94a5e864fa390d449b8fc094ec630b9a823377786f45c702df795b0ffe46bc
5
5
  SHA512:
6
- metadata.gz: 48ac8a047cdbebff3c964498fe062b803ed072c34358964c0f2907b55a34f93a4523d0a2431b8109e441cce049a51a1025ebdb08afd0d81360f4c0a0386f3ce2
7
- data.tar.gz: ddcc2207888fead514c870f8a11c34b26ea037b930c157085685e647cc82d29270688377a657c16319312f1cb4b880ea5a401d8a7de93295dc61f8f14f2bce64
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 unless Dir.exist? 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
- # Parse document part references.
110
+ # Look for "Cite as" references.
110
111
  #
111
112
  # @return [Array<String>] document part references
112
113
  #
@@ -1,4 +1,5 @@
1
1
  module RelatonOasis
2
+ # Common methods for document and part parsers.
2
3
  module DataParserUtils
3
4
  #
4
5
  # Parse document identifier specification.
@@ -1,4 +1,5 @@
1
1
  module RelatonOasis
2
+ # Parser for OASIS part document.
2
3
  class DataPartParser
3
4
  include RelatonOasis::DataParserUtils
4
5
 
@@ -26,7 +27,6 @@ module RelatonOasis
26
27
  #
27
28
  def parse # rubocop:disable Metrics/MethodLength
28
29
  RelatonOasis::OasisBibliographicItem.new(
29
- fetched: Date.today.to_s,
30
30
  type: "standard",
31
31
  doctype: parse_doctype,
32
32
  title: parse_title,
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonOasis
4
- VERSION = "1.14.0"
4
+ VERSION = "1.14.2"
5
5
  end
data/lib/relaton_oasis.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "mechanize"
4
- require "jing"
5
4
  require "relaton_bib"
6
5
  require_relative "relaton_oasis/version"
7
6
  require_relative "relaton_oasis/oasis_bibliographic_item"
@@ -12,6 +11,7 @@ require_relative "relaton_oasis/data_fetcher"
12
11
  require_relative "relaton_oasis/data_parser_utils"
13
12
  require_relative "relaton_oasis/data_parser"
14
13
  require_relative "relaton_oasis/data_part_parser"
14
+ require_relative "relaton_oasis/index"
15
15
 
16
16
  module RelatonOasis
17
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.0
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: 2022-12-05 00:00:00.000000000 Z
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