relaton 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +21 -19
- data/docs/README.adoc +9 -9
- data/lib/relaton/db.rb +41 -77
- data/lib/relaton/db_cache.rb +34 -3
- data/lib/relaton/processor.rb +6 -4
- data/lib/relaton/registry.rb +42 -4
- data/lib/relaton/version.rb +1 -1
- data/relaton.gemspec +3 -2
- data/relaton/cache/version +1 -1
- data/spec/relaton/relaton_spec.rb +7 -0
- data/spec/vcr_cassetes/gb_t_20223_2006.yml +21 -25
- data/spec/vcr_cassetes/iso_iec_guide_2.yml +232 -0
- data/spec/vcr_cassetes/ogc_19_025r1.yml +56 -0
- metadata +19 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa7b97836f446229ce44afbf7a16e269627124e9
|
4
|
+
data.tar.gz: dcd68311f5e954a083a5aa62f5a65cbcf30164cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e67ff8a550e90d17cbc9c8eff20c03158f3d1499b877910c4b690cba55efbd8c51fb0b149c54216764babb8532f38b0090d040326d528b3715fb9a9bea927ec4
|
7
|
+
data.tar.gz: 07cd319987710471a43ee309ca0843880c832f11ad011fe995e91e5d43b98cf4c0d0650c650f295487f84a4a797cf61e432711ed2cdad4ddcbf448c111716f0c
|
data/Gemfile.lock
CHANGED
@@ -1,23 +1,20 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
relaton (0.5.
|
5
|
-
algoliasearch
|
4
|
+
relaton (0.5.4)
|
6
5
|
relaton-gb (~> 0.6.0)
|
7
6
|
relaton-iec (~> 0.4.0)
|
8
7
|
relaton-ietf (~> 0.6.0)
|
9
8
|
relaton-iso (~> 0.6.0)
|
10
9
|
relaton-itu (~> 0.3.0)
|
11
10
|
relaton-nist (~> 0.3.0)
|
11
|
+
relaton-ogc (~> 0.1.0)
|
12
12
|
|
13
13
|
GEM
|
14
14
|
remote: https://rubygems.org/
|
15
15
|
specs:
|
16
|
-
addressable (2.
|
17
|
-
public_suffix (>= 2.0.2, <
|
18
|
-
algoliasearch (1.26.1)
|
19
|
-
httpclient (~> 2.8, >= 2.8.3)
|
20
|
-
json (>= 1.5.1)
|
16
|
+
addressable (2.7.0)
|
17
|
+
public_suffix (>= 2.0.2, < 5.0)
|
21
18
|
ast (2.4.0)
|
22
19
|
byebug (10.0.2)
|
23
20
|
cnccs (0.1.3)
|
@@ -31,6 +28,8 @@ GEM
|
|
31
28
|
docile (1.3.2)
|
32
29
|
equivalent-xml (0.6.0)
|
33
30
|
nokogiri (>= 1.4.3)
|
31
|
+
faraday (0.15.4)
|
32
|
+
multipart-post (>= 1.2, < 3)
|
34
33
|
ffi (1.11.1)
|
35
34
|
formatador (0.2.5)
|
36
35
|
gb-agencies (0.0.5)
|
@@ -49,7 +48,6 @@ GEM
|
|
49
48
|
guard-compat (~> 1.1)
|
50
49
|
rspec (>= 2.99.0, < 4.0)
|
51
50
|
hashdiff (0.4.0)
|
52
|
-
httpclient (2.8.3)
|
53
51
|
isoics (0.1.7)
|
54
52
|
json (2.2.0)
|
55
53
|
listen (3.1.5)
|
@@ -59,6 +57,7 @@ GEM
|
|
59
57
|
lumberjack (1.0.13)
|
60
58
|
method_source (0.9.2)
|
61
59
|
mini_portile2 (2.4.0)
|
60
|
+
multipart-post (2.1.1)
|
62
61
|
nenv (0.3.0)
|
63
62
|
nokogiri (1.10.4)
|
64
63
|
mini_portile2 (~> 2.4.0)
|
@@ -75,36 +74,39 @@ GEM
|
|
75
74
|
pry-byebug (3.6.0)
|
76
75
|
byebug (~> 10.0)
|
77
76
|
pry (~> 0.10)
|
78
|
-
public_suffix (
|
77
|
+
public_suffix (4.0.1)
|
79
78
|
rainbow (3.0.0)
|
80
79
|
rake (12.3.2)
|
81
80
|
rb-fsevent (0.10.3)
|
82
81
|
rb-inotify (0.10.0)
|
83
82
|
ffi (~> 1.0)
|
84
|
-
relaton-bib (0.3.
|
83
|
+
relaton-bib (0.3.6)
|
85
84
|
addressable
|
86
|
-
nokogiri
|
87
|
-
relaton-gb (0.6.
|
85
|
+
nokogiri
|
86
|
+
relaton-gb (0.6.3)
|
88
87
|
cnccs (~> 0.1.1)
|
89
88
|
gb-agencies (~> 0.0.1)
|
90
89
|
relaton-iso-bib (~> 0.3.0)
|
91
|
-
relaton-iec (0.4.
|
90
|
+
relaton-iec (0.4.4)
|
92
91
|
addressable
|
93
92
|
relaton-iso-bib (~> 0.3.0)
|
94
|
-
relaton-ietf (0.6.
|
93
|
+
relaton-ietf (0.6.4)
|
95
94
|
relaton-bib (~> 0.3.0)
|
96
|
-
relaton-iso (0.6.
|
95
|
+
relaton-iso (0.6.5)
|
97
96
|
relaton-iec (~> 0.4.0)
|
98
97
|
relaton-iso-bib (~> 0.3.0)
|
99
|
-
relaton-iso-bib (0.3.
|
98
|
+
relaton-iso-bib (0.3.5)
|
100
99
|
isoics (~> 0.1.6)
|
101
100
|
relaton-bib (~> 0.3.0)
|
102
101
|
ruby_deep_clone (~> 0.8.0)
|
103
|
-
relaton-itu (0.3.
|
102
|
+
relaton-itu (0.3.3)
|
104
103
|
relaton-iso-bib (~> 0.3.0)
|
105
|
-
relaton-nist (0.3.
|
104
|
+
relaton-nist (0.3.4)
|
106
105
|
relaton-bib (~> 0.3.0)
|
107
106
|
rubyzip
|
107
|
+
relaton-ogc (0.1.0)
|
108
|
+
faraday
|
109
|
+
relaton-iso-bib (~> 0.3.0)
|
108
110
|
rspec (3.8.0)
|
109
111
|
rspec-core (~> 3.8.0)
|
110
112
|
rspec-expectations (~> 3.8.0)
|
@@ -130,7 +132,7 @@ GEM
|
|
130
132
|
ruby-progressbar (1.10.1)
|
131
133
|
ruby_deep_clone (0.8.0)
|
132
134
|
ruby_dep (1.5.0)
|
133
|
-
rubyzip (1.2.
|
135
|
+
rubyzip (1.2.4)
|
134
136
|
safe_yaml (1.0.5)
|
135
137
|
shellany (0.0.1)
|
136
138
|
simplecov (0.16.1)
|
data/docs/README.adoc
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
= Relaton
|
2
2
|
|
3
3
|
image:https://img.shields.io/gem/v/relaton.svg["Gem Version", link="https://rubygems.org/gems/relaton"]
|
4
|
-
image:https://img.shields.io/travis/
|
4
|
+
image:https://img.shields.io/travis/relaton/relaton/master.svg["Build Status", link="https://travis-ci.org/relaton/relaton"]
|
5
5
|
image:https://ci.appveyor.com/api/projects/status/rm8mundlocspsue0?svg=true["Appveyor Build Status", link="https://ci.appveyor.com/project/ribose/relaton"]
|
6
|
-
image:https://codeclimate.com/github/
|
6
|
+
image:https://codeclimate.com/github/relaton/relaton/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/relaton/relaton"]
|
7
7
|
|
8
8
|
Gem for importing and caching bibliographic references to technical standards.
|
9
9
|
|
@@ -13,17 +13,17 @@ The Relaton gem obtains authoritative bibliographic entries for technical standa
|
|
13
13
|
|
14
14
|
The gem also caches entries it has retrieved, so that subsequent iterations do not need to go back online to retrieve the same entries. The gem uses two caches: a global cache (for all bibliographic entries retrieved by the user), and a local cache (intended to store references specific to the current document being processed.)
|
15
15
|
|
16
|
-
Entries are retrieved and stored in the https://github.com/
|
16
|
+
Entries are retrieved and stored in the https://github.com/relaton/relaton-models[Relaton bibliographic model], which is an expression of ISO 690. The subset of the model used and serialised for Relaton is defined in the https://github.com/relaton/relaton-bib[relaton-bib] and https://github.com/relaton/relaton-iso-bib[relaton-iso-bib] gems.
|
17
17
|
|
18
|
-
Entries are serialised to and from an internal data model, and multiple formats are intended to be supported. Currently only https://github.com/
|
18
|
+
Entries are serialised to and from an internal data model, and multiple formats are intended to be supported. Currently only https://github.com/relaton/relaton-models/blob/master/grammars/biblio.rnc[Relaton XML] is supported.
|
19
19
|
|
20
20
|
Relaton imports bibliographic entries from:
|
21
21
|
|
22
|
-
* ISO through the iso.org website, via the https://github.com/
|
23
|
-
* IEC through the iec.ch website, via the https://github.com/
|
24
|
-
* GB (Chinese national standards) through the GB websites, via the https://github.com/
|
25
|
-
* IETF standards (Internet Drafts, RFC) through the http://xml2rfc.tools.ietf.org website, via the https://github.com/
|
26
|
-
* NIST standards through the nist.gov website, via the https://github.com/
|
22
|
+
* ISO through the iso.org website, via the https://github.com/relaton/relaton-iso[relaton-iso] gem
|
23
|
+
* IEC through the iec.ch website, via the https://github.com/relaton/relaton-iec[relaton-iec] gem
|
24
|
+
* GB (Chinese national standards) through the GB websites, via the https://github.com/relaton/relaton-gb[relaton-gb] gem
|
25
|
+
* IETF standards (Internet Drafts, RFC) through the http://xml2rfc.tools.ietf.org website, via the https://github.com/relaton/relaton-ietf[relaton-ietf] gem
|
26
|
+
* NIST standards through the nist.gov website, via the https://github.com/relaton/relaton-nist[relaotn-nist] gem
|
27
27
|
|
28
28
|
The identifiers for which bibliographic entries are to be retrieved need to indicate which standards body they belong to. To do so, this gem adopts the convention of bracketing identifiers, and preceding them with a code that indicates the standards body:
|
29
29
|
|
data/lib/relaton/db.rb
CHANGED
@@ -6,44 +6,34 @@ module Relaton
|
|
6
6
|
class RelatonError < StandardError; end
|
7
7
|
|
8
8
|
class Db
|
9
|
-
SUPPORTED_GEMS = %w[
|
10
|
-
relaton_iso relaton_ietf relaton_gb relaton_iec relaton_nist relaton_itu
|
11
|
-
].freeze
|
12
|
-
|
13
9
|
# @param global_cache [String] directory of global DB
|
14
10
|
# @param local_cache [String] directory of local DB
|
15
11
|
def initialize(global_cache, local_cache)
|
16
|
-
register_gems
|
17
12
|
@registry = Relaton::Registry.instance
|
13
|
+
# @registry.register_gems
|
18
14
|
@db = open_cache_biblio(global_cache)
|
19
15
|
@local_db = open_cache_biblio(local_cache, global: false)
|
20
16
|
@db_name = global_cache
|
21
17
|
@local_db_name = local_cache
|
22
18
|
end
|
23
19
|
|
24
|
-
def register_gems
|
25
|
-
puts "[relaton] Info: detecting backends:"
|
26
|
-
SUPPORTED_GEMS.each do |b|
|
27
|
-
# puts b
|
28
|
-
begin
|
29
|
-
require b
|
30
|
-
rescue LoadError
|
31
|
-
puts "[relaton] Error: backend #{b} not present"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
20
|
# The class of reference requested is determined by the prefix of the code:
|
37
21
|
# GB Standard for gbbib, IETF for ietfbib, ISO for isobib, IEC or IEV for iecbib,
|
38
22
|
# @param code [String] the ISO standard Code to look up (e.g. "ISO 9000")
|
39
23
|
# @param year [String] the year the standard was published (optional)
|
40
24
|
# @param opts [Hash] options; restricted to :all_parts if all-parts reference is required
|
41
|
-
# @return [
|
25
|
+
# @return [NilClass, RelatonIsoBib::IsoBibliographicItem,
|
26
|
+
# RelatonItu::ItuBibliographicItem, RelatonIetf::IetfBibliographicItem,
|
27
|
+
# RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem]
|
42
28
|
def fetch(code, year = nil, opts = {})
|
43
29
|
stdclass = standard_class(code) or return nil
|
44
30
|
check_bibliocache(code, year, opts, stdclass)
|
45
31
|
end
|
46
32
|
|
33
|
+
# @param code [String]
|
34
|
+
# @param year [String, NilClass]
|
35
|
+
# @param stdclass [Symbol, NilClass]
|
36
|
+
# @param opts [Hash]
|
47
37
|
def fetch_std(code, year = nil, stdclass = nil, opts = {})
|
48
38
|
std = nil
|
49
39
|
@registry.processors.each do |name, processor|
|
@@ -55,14 +45,9 @@ module Relaton
|
|
55
45
|
check_bibliocache(code, year, opts, std)
|
56
46
|
end
|
57
47
|
|
58
|
-
# def fetched(key)
|
59
|
-
# return @local_db.fetched key if @local_db
|
60
|
-
# return @db.fetched key if @db
|
61
|
-
|
62
|
-
# ""
|
63
|
-
# end
|
64
|
-
|
65
48
|
# The document identifier class corresponding to the given code
|
49
|
+
# @param code [String]
|
50
|
+
# @return [Array]
|
66
51
|
def docid_type(code)
|
67
52
|
stdclass = standard_class(code) or return [nil, code]
|
68
53
|
_prefix, code = strip_id_wrapper(code, stdclass)
|
@@ -126,7 +111,7 @@ module Relaton
|
|
126
111
|
ret = code
|
127
112
|
ret += ":#{year}" if year
|
128
113
|
ret += " (all parts)" if opts[:all_parts]
|
129
|
-
["#{prefix}(#{ret})", code]
|
114
|
+
["#{prefix}(#{ret.strip})", code]
|
130
115
|
end
|
131
116
|
|
132
117
|
# Find prefix and clean code
|
@@ -139,6 +124,11 @@ module Relaton
|
|
139
124
|
[prefix, code]
|
140
125
|
end
|
141
126
|
|
127
|
+
# @param entry [String] XML string
|
128
|
+
# @param stdclass [Symbol]
|
129
|
+
# @return [NilClass, RelatonIsoBib::IsoBibliographicItem,
|
130
|
+
# RelatonItu::ItuBibliographicItem, RelatonIetf::IetfBibliographicItem,
|
131
|
+
# RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem]
|
142
132
|
def bib_retval(entry, stdclass)
|
143
133
|
entry =~ /^not_found/ ? nil : @registry.processors[stdclass].from_xml(entry)
|
144
134
|
end
|
@@ -147,6 +137,9 @@ module Relaton
|
|
147
137
|
# @param year [String]
|
148
138
|
# @param opts [Hash]
|
149
139
|
# @param stdclass [Symbol]
|
140
|
+
# @return [NilClass, RelatonIsoBib::IsoBibliographicItem,
|
141
|
+
# RelatonItu::ItuBibliographicItem, RelatonIetf::IetfBibliographicItem,
|
142
|
+
# RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem]
|
150
143
|
def check_bibliocache(code, year, opts, stdclass)
|
151
144
|
id, searchcode = std_id(code, year, opts, stdclass)
|
152
145
|
db = @local_db || @db
|
@@ -155,35 +148,40 @@ module Relaton
|
|
155
148
|
|
156
149
|
db.delete(id) unless db.valid_entry?(id, year)
|
157
150
|
if altdb
|
158
|
-
db[id] ||= altdb[id]
|
159
|
-
db
|
160
|
-
|
151
|
+
# db[id] ||= altdb[id]
|
152
|
+
db.clone_entry id, altdb
|
153
|
+
db[id] ||= new_bib_entry(searchcode, year, opts, stdclass, db, id)
|
154
|
+
altdb.clone_entry(id, db) if !altdb.valid_entry?(id, year)
|
161
155
|
else
|
162
|
-
db[id] ||= new_bib_entry(searchcode, year, opts, stdclass)
|
156
|
+
db[id] ||= new_bib_entry(searchcode, year, opts, stdclass, db, id)
|
163
157
|
end
|
164
158
|
bib_retval(db[id], stdclass)
|
165
159
|
end
|
166
160
|
|
167
|
-
# hash uses => , because the hash is imported from JSON
|
168
161
|
# @param code [String]
|
169
162
|
# @param year [String]
|
170
163
|
# @param opts [Hash]
|
171
164
|
# @param stdclass [Symbol]
|
172
|
-
# @return [
|
173
|
-
def new_bib_entry(code, year, opts, stdclass)
|
165
|
+
# @return [String]
|
166
|
+
def new_bib_entry(code, year, opts, stdclass, db = nil, id = nil)
|
174
167
|
bib = @registry.processors[stdclass].get(code, year, opts)
|
175
|
-
|
176
|
-
|
177
|
-
|
168
|
+
bib_id = bib&.docidentifier&.first&.id&.sub(%r{(?<=\d)-(?=\d{4})}, ":")
|
169
|
+
if db && id && bib_id && id !~ %r{\(#{bib_id}\)}
|
170
|
+
bid = std_id(bib.docidentifier.first.id, nil, {}, stdclass).first
|
171
|
+
db[bid] ||= bib_entry bib
|
172
|
+
"redirection #{bid}"
|
173
|
+
else
|
174
|
+
bib_entry bib
|
175
|
+
end
|
178
176
|
end
|
179
177
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
178
|
+
def bib_entry(bib)
|
179
|
+
if bib.respond_to? :to_xml
|
180
|
+
bib.to_xml(bibdata: true)
|
181
|
+
else
|
182
|
+
"not_found #{Date.today}"
|
183
|
+
end
|
184
|
+
end
|
187
185
|
|
188
186
|
# @param dir [String] DB directory
|
189
187
|
# @param global [TrueClass, FalseClass]
|
@@ -204,39 +202,5 @@ module Relaton
|
|
204
202
|
nil
|
205
203
|
end
|
206
204
|
end
|
207
|
-
|
208
|
-
# Check if version of the DB match to the gem version.
|
209
|
-
# @param cache_db [String] DB directory
|
210
|
-
# @return [TrueClass, FalseClass]
|
211
|
-
# def check_cache_version(cache_db)
|
212
|
-
# cache_db.transaction { cache_db[:version] == VERSION }
|
213
|
-
# end
|
214
|
-
|
215
|
-
# Set version of the DB to the gem version.
|
216
|
-
# @param cache_db [String] DB directory
|
217
|
-
# @return [Pstore]
|
218
|
-
# def set_cache_version(cache_db)
|
219
|
-
# unless File.exist? cache_db.path
|
220
|
-
# cache_db.transaction { cache_db[:version] = VERSION }
|
221
|
-
# end
|
222
|
-
# cache_db
|
223
|
-
# end
|
224
|
-
|
225
|
-
# @param enstry [String] entry in XML format
|
226
|
-
# @return [IsoBibItem::IsoBibliographicItem]
|
227
|
-
# def from_xml(entry)
|
228
|
-
# IsoBibItem.from_xml entry # will be unmarshaller
|
229
|
-
# end
|
230
|
-
|
231
|
-
# @param [Hash{String=>Hash{String=>String}}] biblio
|
232
|
-
# def save_cache_biblio(biblio, filename)
|
233
|
-
# return if biblio.nil? || filename.nil?
|
234
|
-
# File.open(filename, "w") do |b|
|
235
|
-
# b << biblio.reduce({}) do |s, (k, v)|
|
236
|
-
# bib = v["bib"].respond_to?(:to_xml) ? v["bib"].to_xml : v["bib"]
|
237
|
-
# s.merge(k => { "fetched" => v["fetched"], "bib" => bib })
|
238
|
-
# end.to_json
|
239
|
-
# end
|
240
|
-
# end
|
241
205
|
end
|
242
206
|
end
|
data/lib/relaton/db_cache.rb
CHANGED
@@ -31,10 +31,19 @@ module Relaton
|
|
31
31
|
# @param key [String]
|
32
32
|
# @return [String]
|
33
33
|
def [](key)
|
34
|
-
|
35
|
-
|
34
|
+
value = get(key)
|
35
|
+
if (code = redirect? value)
|
36
|
+
self[code]
|
37
|
+
else
|
38
|
+
value
|
39
|
+
end
|
40
|
+
end
|
36
41
|
|
37
|
-
|
42
|
+
def clone_entry(key, db)
|
43
|
+
self[key] ||= db.get(key)
|
44
|
+
if (code = redirect? get(key))
|
45
|
+
clone_entry code, db
|
46
|
+
end
|
38
47
|
end
|
39
48
|
|
40
49
|
# Return fetched date
|
@@ -92,8 +101,30 @@ module Relaton
|
|
92
101
|
year || Date.today - date < 60
|
93
102
|
end
|
94
103
|
|
104
|
+
protected
|
105
|
+
|
106
|
+
# Reads file by a key
|
107
|
+
#
|
108
|
+
# @param key [String]
|
109
|
+
# @return [String, NilClass]
|
110
|
+
def get(key)
|
111
|
+
file = filename key
|
112
|
+
return unless File.exist? file
|
113
|
+
|
114
|
+
File.read(file, encoding: "utf-8")
|
115
|
+
end
|
116
|
+
|
95
117
|
private
|
96
118
|
|
119
|
+
# Check if a file content is redirection
|
120
|
+
#
|
121
|
+
# @prarm value [String] file content
|
122
|
+
# @return [String, NilClass] redirection code or nil
|
123
|
+
def redirect?(value)
|
124
|
+
%r{redirection\s(?<code>.*)} =~ value
|
125
|
+
code
|
126
|
+
end
|
127
|
+
|
97
128
|
# Return item's file name
|
98
129
|
# @param key [String]
|
99
130
|
# @return [String]
|
data/lib/relaton/processor.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Relaton
|
2
2
|
class Processor
|
3
|
-
|
4
3
|
attr_reader :short
|
5
4
|
attr_reader :prefix
|
6
5
|
attr_reader :defaultprefix
|
@@ -10,13 +9,16 @@ module Relaton
|
|
10
9
|
raise "This is an abstract class!"
|
11
10
|
end
|
12
11
|
|
13
|
-
def get(
|
12
|
+
def get(_code, _date, _opts)
|
14
13
|
raise "This is an abstract class!"
|
15
14
|
end
|
16
15
|
|
17
|
-
def from_xml(
|
16
|
+
def from_xml(_xml)
|
17
|
+
raise "This is an abstract class!"
|
18
|
+
end
|
19
|
+
|
20
|
+
def hash_to_bib(_hash)
|
18
21
|
raise "This is an abstract class!"
|
19
22
|
end
|
20
23
|
end
|
21
24
|
end
|
22
|
-
|
data/lib/relaton/registry.rb
CHANGED
@@ -5,27 +5,65 @@ end
|
|
5
5
|
|
6
6
|
module Relaton
|
7
7
|
class Registry
|
8
|
+
SUPPORTED_GEMS = %w[
|
9
|
+
relaton_gb relaton_iec relaton_ietf relaton_iso relaton_itu relaton_nist
|
10
|
+
relaton_ogc
|
11
|
+
].freeze
|
12
|
+
|
8
13
|
include Singleton
|
9
14
|
|
10
15
|
attr_reader :processors
|
11
16
|
|
12
17
|
def initialize
|
13
18
|
@processors = {}
|
19
|
+
register_gems
|
20
|
+
end
|
21
|
+
|
22
|
+
def register_gems
|
23
|
+
puts "[relaton] Info: detecting backends:"
|
24
|
+
SUPPORTED_GEMS.each do |b|
|
25
|
+
begin
|
26
|
+
require b
|
27
|
+
require "#{b}/processor"
|
28
|
+
register Kernel.const_get "#{camel_case(b)}::Processor"
|
29
|
+
rescue LoadError
|
30
|
+
puts "[relaton] Error: backend #{b} not present"
|
31
|
+
end
|
32
|
+
end
|
14
33
|
end
|
15
34
|
|
16
35
|
def register(processor)
|
17
|
-
raise Error unless processor < ::
|
36
|
+
raise Error unless processor < ::Relaton::Processor
|
37
|
+
|
18
38
|
p = processor.new
|
39
|
+
return if processors[p.short]
|
40
|
+
|
19
41
|
puts "[relaton] processor \"#{p.short}\" registered"
|
20
|
-
|
42
|
+
processors[p.short] = p
|
21
43
|
end
|
22
44
|
|
23
45
|
def find_processor(short)
|
24
|
-
|
46
|
+
processors[short.to_sym]
|
25
47
|
end
|
26
48
|
|
49
|
+
# @return [Array]
|
27
50
|
def supported_processors
|
28
|
-
|
51
|
+
processors.keys
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Find processor by type
|
56
|
+
#
|
57
|
+
# @param type [String]
|
58
|
+
# @return [Relaton::RelatonIso::Processor]
|
59
|
+
def by_type(type)
|
60
|
+
processors.values.detect { |v| v.idtype == type }
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def camel_case(gem_name)
|
66
|
+
gem_name.split("_").map(&:capitalize).join
|
29
67
|
end
|
30
68
|
end
|
31
69
|
end
|