relaton-core 0.0.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 +7 -0
- data/LICENSE.txt +25 -0
- data/README.adoc +46 -0
- data/lib/relaton/core/data_fetcher.rb +104 -0
- data/lib/relaton/core/version.rb +5 -0
- data/lib/relaton/core.rb +3 -0
- data/lib/relaton-core.rb +1 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e57b8db4577d599195b3948fdc1a5bf213d3e97e17c1b5d38dfa942e00130c18
|
4
|
+
data.tar.gz: d34080a4e6dd2e717ce35c80dc869c2630ffcf7d93a1358e05e4fcab4f878659
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0cb84f4a86ab0a3ff56c7c8639b5ff677a76bc189043a61c5bbd104a0950ec4f195a3e4fe952a47b72e0430066ffd3940042823250e47acc611c7a33799d1520
|
7
|
+
data.tar.gz: 1f8118680baa7149459c6e6d4a800cee274e594e1b28cbbac35677be12c2b655d4666065b150719f10348bf72b31ff7c629057078f71798a55198d2e97b2c96d
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
BSD 2-Clause License
|
2
|
+
|
3
|
+
Copyright (c) 2018, Ribose
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
* Redistributions of source code must retain the above copyright notice, this
|
10
|
+
list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
14
|
+
and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
20
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
21
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
22
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
23
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
24
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
25
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.adoc
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
= Library for importing and caching bibliographic references to technical standards library
|
2
|
+
|
3
|
+
== Usage
|
4
|
+
|
5
|
+
=== Exclude attributes when compare
|
6
|
+
|
7
|
+
[source,ruby]
|
8
|
+
----
|
9
|
+
require "relaton-core"
|
10
|
+
|
11
|
+
pubid_first = Identifier.parse("ISO 1:1999")
|
12
|
+
pubid_second = Identifier.parse("ISO 1")
|
13
|
+
|
14
|
+
pubid_first == pubid_second
|
15
|
+
=> false
|
16
|
+
|
17
|
+
pubid_first.exclude(:year) == pubid_second
|
18
|
+
=> true
|
19
|
+
----
|
20
|
+
|
21
|
+
=== Using #to_h to convert identifier to hash
|
22
|
+
|
23
|
+
[source,ruby]
|
24
|
+
----
|
25
|
+
require "pubid-core"
|
26
|
+
|
27
|
+
pubid = Identifier.parse("ISO 1:1999")
|
28
|
+
pubid.to_h
|
29
|
+
=> { publisher: "ISO", number: 1, year: 1999 }
|
30
|
+
----
|
31
|
+
|
32
|
+
=== Using #new_edition_of? to compare identifiers
|
33
|
+
|
34
|
+
[source,ruby]
|
35
|
+
----
|
36
|
+
require "pubid-core"
|
37
|
+
|
38
|
+
pubid_first = Identifier.parse("ISO 1:1999")
|
39
|
+
pubid_second = Identifier.parse("ISO 1:2000")
|
40
|
+
|
41
|
+
pubid_first.new_edition_of?(pubid_second)
|
42
|
+
=> false
|
43
|
+
pubid_second.new_edition_of?(pubid_first)
|
44
|
+
=> true
|
45
|
+
|
46
|
+
----
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Relaton::Core
|
2
|
+
class DataFetcher
|
3
|
+
attr_accessor :docs
|
4
|
+
#
|
5
|
+
# Initialize fetcher
|
6
|
+
#
|
7
|
+
# @param [String] output path to output directory
|
8
|
+
# @param [String] format output format (yaml, xml, bibxml)
|
9
|
+
#
|
10
|
+
def initialize(output, format)
|
11
|
+
@output = output
|
12
|
+
@format = format
|
13
|
+
@ext = format.sub "bibxml", "xml"
|
14
|
+
@files = []
|
15
|
+
@docs = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def index
|
19
|
+
@index ||= Relaton::Index.find_or_create self.class::INDEX_TYPE,
|
20
|
+
file: self.class::INDEX_FILE,
|
21
|
+
pubid_class: self.class.get_identifier_class
|
22
|
+
end
|
23
|
+
|
24
|
+
# API method for external service
|
25
|
+
def self.fetch(output: "data", format: "yaml")
|
26
|
+
t1 = Time.now
|
27
|
+
puts "Started at: #{t1}"
|
28
|
+
FileUtils.mkdir_p output
|
29
|
+
new(output, format).fetch
|
30
|
+
t2 = Time.now
|
31
|
+
puts "Stopped at: #{t2}"
|
32
|
+
puts "Done in: #{(t2 - t1).round} sec."
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.get_identifier_class
|
36
|
+
raise NotImplementedError, "#{self.class}#get_identifier_class method must be implemented"
|
37
|
+
end
|
38
|
+
|
39
|
+
def fetch
|
40
|
+
fetch_docs ACTIVE_PUBS_URL
|
41
|
+
fetch_docs OBSOLETE_PUBS_URL, retired: true
|
42
|
+
index.save
|
43
|
+
end
|
44
|
+
|
45
|
+
# Parse hash and return RelatonBib
|
46
|
+
# @param [Hash] doc document data
|
47
|
+
# @return [RelatonBib]
|
48
|
+
def parse(doc)
|
49
|
+
raise NotImplementedError, "#{self.class}#parse method must be implemented"
|
50
|
+
end
|
51
|
+
|
52
|
+
# @param [RelatonBib::BibliographicItem] bib
|
53
|
+
# @return [String] filename based on PubID identifier
|
54
|
+
def get_output_file(bib)
|
55
|
+
File.join @output, "#{bib.docidentifier.first.id.gsub(/[.\s-]+/, '-')}.#{@ext}"
|
56
|
+
end
|
57
|
+
|
58
|
+
#
|
59
|
+
# Parse document and save to file
|
60
|
+
#
|
61
|
+
# @param [Hash] doc document data
|
62
|
+
# @param [Boolean] retired if true then document is retired
|
63
|
+
#
|
64
|
+
# @return [void]
|
65
|
+
#
|
66
|
+
def parse_and_save(doc)
|
67
|
+
bibitem = parse(doc)
|
68
|
+
save_bib(bibitem)
|
69
|
+
index_add_or_update(bibitem)
|
70
|
+
end
|
71
|
+
|
72
|
+
#
|
73
|
+
# Save bibitem to file
|
74
|
+
#
|
75
|
+
# @param [RelatonBib::BibliographicItem] bib bibitem
|
76
|
+
#
|
77
|
+
# @return [void]
|
78
|
+
#
|
79
|
+
def save_bib(bib)
|
80
|
+
file = get_output_file(bib)
|
81
|
+
File.write file, serialize(bib), encoding: "UTF-8"
|
82
|
+
end
|
83
|
+
|
84
|
+
def index_add_or_update(bib)
|
85
|
+
index.add_or_update self.class.get_identifier_class.parse(bib.docidentifier.first.id),
|
86
|
+
get_output_file(bib)
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Serialize bibliographic item
|
91
|
+
#
|
92
|
+
# @param [RelatonCcsds::BibliographicItem] bib <description>
|
93
|
+
#
|
94
|
+
# @return [String] serialized bibliographic item
|
95
|
+
#
|
96
|
+
def serialize(bib)
|
97
|
+
case @format
|
98
|
+
when "yaml" then bib.to_hash.to_yaml
|
99
|
+
when "xml" then bib.to_xml(bibdata: true)
|
100
|
+
else bib.send "to_#{@format}"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/lib/relaton/core.rb
ADDED
data/lib/relaton-core.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "relaton/core"
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: relaton-core
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ribose Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-01-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '13.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '13.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: relaton-bib
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.19.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.19.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: relaton-index
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.2.16
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.2.16
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pubid-core
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.12.10
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.12.10
|
83
|
+
description: Library for importing and caching bibliographic references to technical
|
84
|
+
standards
|
85
|
+
email:
|
86
|
+
- open.source@ribose.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files:
|
90
|
+
- README.adoc
|
91
|
+
- LICENSE.txt
|
92
|
+
files:
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.adoc
|
95
|
+
- lib/relaton-core.rb
|
96
|
+
- lib/relaton/core.rb
|
97
|
+
- lib/relaton/core/data_fetcher.rb
|
98
|
+
- lib/relaton/core/version.rb
|
99
|
+
homepage: https://github.com/relaton/relaton-core
|
100
|
+
licenses:
|
101
|
+
- BSD-2-Clause
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 2.5.0
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubygems_version: 3.3.27
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: Library for importing and caching bibliographic references to technical standards
|
122
|
+
test_files: []
|