relaton 0.0.2 → 0.1.0

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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -0
  3. data/.travis.yml +9 -1
  4. data/Gemfile.lock +18 -134
  5. data/README.adoc +7 -4
  6. data/Rakefile +6 -0
  7. data/lib/relaton/db.rb +92 -45
  8. data/lib/relaton/registry.rb +2 -7
  9. data/lib/relaton/version.rb +1 -1
  10. data/relaton.gemspec +5 -6
  11. data/spec/relaton/relaton_spec.rb +72 -68
  12. data/spec/support/iso_111111119115_1.xml +0 -0
  13. data/spec/support/iso_19115_1.xml +117 -0
  14. data/spec/support/iso_19115_2.xml +97 -0
  15. data/spec/support/list_entries.xml +113 -0
  16. metadata +34 -74
  17. data/spec/support/_fr_standard_26020.html +0 -828
  18. data/spec/support/_fr_standard_32557.html +0 -843
  19. data/spec/support/_fr_standard_32579.html +0 -768
  20. data/spec/support/_fr_standard_39229.html +0 -880
  21. data/spec/support/_fr_standard_44361.html +0 -606
  22. data/spec/support/_fr_standard_53798.html +0 -850
  23. data/spec/support/_fr_standard_57104.html +0 -805
  24. data/spec/support/_fr_standard_66197.html +0 -768
  25. data/spec/support/_fr_standard_67039.html +0 -704
  26. data/spec/support/_fr_standard_73118.html +0 -775
  27. data/spec/support/_ru_standard_26020.html +0 -831
  28. data/spec/support/_ru_standard_32557.html +0 -841
  29. data/spec/support/_ru_standard_32579.html +0 -772
  30. data/spec/support/_ru_standard_39229.html +0 -872
  31. data/spec/support/_ru_standard_44361.html +0 -597
  32. data/spec/support/_ru_standard_53798.html +0 -843
  33. data/spec/support/_ru_standard_57104.html +0 -803
  34. data/spec/support/_ru_standard_66197.html +0 -767
  35. data/spec/support/_ru_standard_67039.html +0 -695
  36. data/spec/support/_ru_standard_73118.html +0 -768
  37. data/spec/support/_standard_26020.html +0 -840
  38. data/spec/support/_standard_32557.html +0 -848
  39. data/spec/support/_standard_32579.html +0 -779
  40. data/spec/support/_standard_39229.html +0 -879
  41. data/spec/support/_standard_44361.html +0 -606
  42. data/spec/support/_standard_53798.html +0 -850
  43. data/spec/support/_standard_57104.html +0 -810
  44. data/spec/support/_standard_66197.html +0 -774
  45. data/spec/support/_standard_67039.html +0 -704
  46. data/spec/support/_standard_73118.html +0 -775
  47. data/spec/support/algolia_resp_page_0.json +0 -130
  48. data/spec/support/algolia_resp_page_1.json +0 -148
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c97ee373e8454f0e9bc2050074e3a291dd19af6eb7e4caf82b4fdf7f1a81f85
4
- data.tar.gz: c295361c298708f5cc21155d15b5f7c96e7526f46e1986d0c7d5dea8ef466ddb
3
+ metadata.gz: bec19dd26e20ad03b8e537bbfcaab9f5cf75dc005ab71d83a094c99b80f08aaa
4
+ data.tar.gz: 161b82000e567929a9a3faa39669acbfd4528dd6c1ff6dab6610314248b85553
5
5
  SHA512:
6
- metadata.gz: 2dc0a45b6022acc12df6026babdf0a3e1aadc1af73a08238afce32a4b4053f7db36290cfcc1edd14aa1ef5401fb3b9f16e71e25c931944afd549a5b5cc19f414
7
- data.tar.gz: e9b37a99f8269b7bcf48be11c5ac2cd6955c00fa32d2b21416fbd60f377473c93b47e26d3af96a62e45e9d3fecf4ff873953fe91ecfdeffd584f94ca7a6413a1
6
+ metadata.gz: c56f8d929682c8bde40d0b559cb3f5879107dd9bae7032551dbe6a6923555cc5c8107411f73db57d7150b35f8fa8cd9cb807a67b4a170ef855921fbf07ba8e21
7
+ data.tar.gz: 51c4e74ee9e8610b1bd49d972bbcda8e210355f949be4f264af8beb632fe7eb5fc27ed2dcbbd15201e38c5a91f107e6957e9c6fbfc380ba5728fe3469bd7ac35
@@ -0,0 +1,6 @@
1
+ coverage/
2
+ .byebug_history
3
+ .rspec_status
4
+
5
+ testcache
6
+ testcache2
@@ -1,6 +1,14 @@
1
+ dist: trusty
1
2
  sudo: false
2
3
  language: ruby
3
4
  rvm:
4
- - 2.4.3
5
+ - 2.5
6
+ - 2.4
7
+ - ruby-head
5
8
  before_install:
6
9
  - gem install bundler -v 1.16.1
10
+ - unset _JAVA_OPTIONS
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: ruby-head
14
+
@@ -1,12 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- relaton (0.0.1)
5
- asciidoctor (~> 1.5.7)
4
+ relaton (0.0.2)
5
+ algoliasearch
6
6
  gbbib (~> 0.1.0)
7
7
  iev (~> 0.1.0)
8
- iso-bib-item (~> 0.1.6)
9
- isobib (~> 0.1.8)
8
+ isobib (~> 0.2.0)
10
9
  rfcbib (~> 0.1.0)
11
10
 
12
11
  GEM
@@ -15,81 +14,17 @@ GEM
15
14
  algoliasearch (1.23.2)
16
15
  httpclient (~> 2.8, >= 2.8.3)
17
16
  json (>= 1.5.1)
18
- asciidoctor (1.5.7.1)
19
- asciidoctor-csand (0.3.1)
20
- asciidoctor (~> 1.5.7)
21
- asciidoctor-iso (>= 0.9.0)
22
- asciimath
23
- htmlentities (~> 4.3.4)
24
- image_size
25
- isodoc (>= 0.8.0)
26
- mime-types
27
- nokogiri
28
- ruby-jing
29
- ruby-xslt
30
- thread_safe
31
- uuidtools
32
- asciidoctor-csd (0.4.1)
33
- asciidoctor-iso (>= 0.9.0)
34
- isodoc (>= 0.8.0)
35
- asciidoctor-gb (0.3.1)
36
- asciidoctor-iso (>= 0.9.0)
37
- gbbib
38
- isodoc (>= 0.8.0)
39
- twitter_cldr
40
- asciidoctor-iso (0.9.3)
41
- asciidoctor (~> 1.5.7)
42
- iso-bib-item (~> 0.1.6)
43
- isobib (~> 0.1.8)
44
- isodoc (>= 0.8)
45
- ruby-jing
46
- asciidoctor-m3d (0.3.2)
47
- asciidoctor (~> 1.5.7)
48
- asciidoctor-iso (>= 0.9.0)
49
- asciimath
50
- htmlentities (~> 4.3.4)
51
- image_size
52
- isodoc (>= 0.8.0)
53
- mime-types
54
- nokogiri
55
- ruby-jing
56
- ruby-xslt
57
- thread_safe
58
- uuidtools
59
- asciidoctor-rfc (0.9.0)
60
- asciidoctor (~> 1.5.7)
61
- htmlentities (~> 4.3.4)
62
- nokogiri
63
- ruby-jing
64
- thread_safe
65
- asciidoctor-rsd (0.3.1)
66
- asciidoctor (~> 1.5.7)
67
- asciidoctor-iso (>= 0.8.0)
68
- asciimath
69
- htmlentities (~> 4.3.4)
70
- image_size
71
- isodoc (>= 0.7.0)
72
- mime-types
73
- nokogiri
74
- ruby-jing
75
- ruby-xslt
76
- thread_safe
77
- uuidtools
78
- asciimath (1.0.4)
79
17
  ast (2.4.0)
80
18
  byebug (9.1.0)
81
- camertron-eprun (1.1.1)
82
- cldr-plurals-runtime-rb (1.0.1)
83
19
  cnccs (0.1.1)
84
20
  coderay (1.1.2)
85
21
  diff-lcs (1.3)
86
22
  docile (1.3.1)
87
- duplicate (1.1.1)
88
23
  equivalent-xml (0.6.0)
89
24
  nokogiri (>= 1.4.3)
90
25
  ffi (1.9.25)
91
26
  formatador (0.2.5)
92
- gbbib (0.1.3)
27
+ gbbib (0.1.4)
93
28
  cnccs
94
29
  iso-bib-item
95
30
  guard (2.14.2)
@@ -106,62 +41,25 @@ GEM
106
41
  guard (~> 2.1)
107
42
  guard-compat (~> 1.1)
108
43
  rspec (>= 2.99.0, < 4.0)
109
- html2doc (0.8.0)
110
- asciimath
111
- htmlentities (~> 4.3.4)
112
- image_size
113
- mime-types
114
- nokogiri
115
- ruby-xslt
116
- thread_safe
117
- uuidtools
118
- htmlentities (4.3.4)
119
44
  httpclient (2.8.3)
120
45
  iev (0.1.0)
121
46
  nokogiri
122
- image_size (2.0.0)
123
- iso-bib-item (0.1.10)
124
- duplicate (~> 1.1.1)
47
+ iso-bib-item (0.2.0)
125
48
  isoics (~> 0.1.6)
126
- nokogiri
127
- isobib (0.1.9)
49
+ nokogiri (~> 1.8.4)
50
+ ruby_deep_clone (~> 0.8.0)
51
+ isobib (0.2.0)
128
52
  algoliasearch
129
- iso-bib-item (~> 0.1.10)
130
- isodoc (0.8.1)
131
- asciimath
132
- html2doc (>= 0.7.1)
133
- htmlentities (~> 4.3.4)
134
- image_size
135
- liquid
136
- mime-types
137
- nokogiri
138
- roman-numerals
139
- ruby-xslt
140
- sass
141
- thread_safe
142
- uuidtools
53
+ iso-bib-item (~> 0.2.0)
143
54
  isoics (0.1.6)
144
55
  jaro_winkler (1.5.1)
145
56
  json (2.1.0)
146
- liquid (4.0.0)
147
57
  listen (3.1.5)
148
58
  rb-fsevent (~> 0.9, >= 0.9.4)
149
59
  rb-inotify (~> 0.9, >= 0.9.7)
150
60
  ruby_dep (~> 1.2)
151
61
  lumberjack (1.0.13)
152
- metanorma (0.2.5)
153
- asciidoctor-csand (>= 0.3.0)
154
- asciidoctor-csd (>= 0.4.0)
155
- asciidoctor-gb (>= 0.3.0)
156
- asciidoctor-iso (>= 0.9.1)
157
- asciidoctor-m3d (>= 0.3.1)
158
- asciidoctor-rfc (>= 0.9.0)
159
- asciidoctor-rsd (>= 0.3.0)
160
- isodoc (>= 0.8.0)
161
62
  method_source (0.9.0)
162
- mime-types (3.1)
163
- mime-types-data (~> 3.2015)
164
- mime-types-data (3.2016.0521)
165
63
  mini_portile2 (2.3.0)
166
64
  nenv (0.3.0)
167
65
  nokogiri (1.8.4)
@@ -169,22 +67,23 @@ GEM
169
67
  notiffany (0.1.1)
170
68
  nenv (~> 0.1)
171
69
  shellany (~> 0.0)
172
- optout (0.0.2)
173
70
  parallel (1.12.1)
174
- parser (2.5.1.0)
71
+ parser (2.5.1.2)
175
72
  ast (~> 2.4.0)
176
73
  powerpack (0.1.2)
177
74
  pry (0.11.3)
178
75
  coderay (~> 1.1.0)
179
76
  method_source (~> 0.9.0)
77
+ pry-byebug (3.5.1)
78
+ byebug (~> 9.1)
79
+ pry (~> 0.10)
180
80
  rainbow (3.0.0)
181
81
  rake (12.3.1)
182
82
  rb-fsevent (0.10.3)
183
83
  rb-inotify (0.9.10)
184
84
  ffi (>= 0.5.0, < 2)
185
85
  rfcbib (0.1.1)
186
- iso-bib-item (~> 0.1.10)
187
- roman-numerals (0.3.0)
86
+ iso-bib-item (~> 0.2.0)
188
87
  rspec (3.7.0)
189
88
  rspec-core (~> 3.7.0)
190
89
  rspec-expectations (~> 3.7.0)
@@ -198,24 +97,17 @@ GEM
198
97
  diff-lcs (>= 1.2.0, < 2.0)
199
98
  rspec-support (~> 3.7.0)
200
99
  rspec-support (3.7.1)
201
- rubocop (0.57.2)
100
+ rubocop (0.58.1)
202
101
  jaro_winkler (~> 1.5.1)
203
102
  parallel (~> 1.10)
204
- parser (>= 2.5)
103
+ parser (>= 2.5, != 2.5.1.1)
205
104
  powerpack (~> 0.1)
206
105
  rainbow (>= 2.2.2, < 4.0)
207
106
  ruby-progressbar (~> 1.7)
208
107
  unicode-display_width (~> 1.0, >= 1.0.1)
209
- ruby-jing (0.0.1)
210
- optout (>= 0.0.2)
211
108
  ruby-progressbar (1.9.0)
212
- ruby-xslt (0.9.10)
109
+ ruby_deep_clone (0.8.0)
213
110
  ruby_dep (1.5.0)
214
- sass (3.5.6)
215
- sass-listen (~> 4.0.0)
216
- sass-listen (4.0.0)
217
- rb-fsevent (~> 0.9, >= 0.9.4)
218
- rb-inotify (~> 0.9, >= 0.9.7)
219
111
  shellany (0.0.1)
220
112
  simplecov (0.16.1)
221
113
  docile (~> 1.1)
@@ -223,16 +115,8 @@ GEM
223
115
  simplecov-html (~> 0.10.0)
224
116
  simplecov-html (0.10.2)
225
117
  thor (0.20.0)
226
- thread_safe (0.3.6)
227
118
  timecop (0.9.1)
228
- twitter_cldr (4.4.3)
229
- camertron-eprun
230
- cldr-plurals-runtime-rb (~> 1.0)
231
- tzinfo
232
- tzinfo (1.2.5)
233
- thread_safe (~> 0.1)
234
119
  unicode-display_width (1.4.0)
235
- uuidtools (2.1.5)
236
120
 
237
121
  PLATFORMS
238
122
  ruby
@@ -243,7 +127,7 @@ DEPENDENCIES
243
127
  equivalent-xml (~> 0.6)
244
128
  guard (~> 2.14)
245
129
  guard-rspec (~> 4.7)
246
- metanorma (~> 0.2.5)
130
+ pry-byebug
247
131
  rake (~> 12.0)
248
132
  relaton!
249
133
  rspec (~> 3.6)
@@ -1,8 +1,13 @@
1
1
  = relaton
2
2
 
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/riboseinc/relaton/master.svg["Build Status", link="https://travis-ci.org/riboseinc/relaton"]
5
+ image:https://codeclimate.com/github/riboseinc/relaton/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/riboseinc/relaton"]
6
+
3
7
  gem for importing and caching bibliographic references to technical standards
4
8
 
5
- ```ruby
9
+ [source,ruby]
10
+ ----
6
11
  x = Relaton.fetch("ISO19011")
7
12
  => Relaton::Error "No such fetcher"
8
13
 
@@ -12,6 +17,4 @@ x = Relaton.fetch("ISO19011")
12
17
 
13
18
  x.to_xml
14
19
  => <bib-item ...>
15
- ```
16
-
17
-
20
+ ----
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -1,3 +1,4 @@
1
+ require "pstore"
1
2
  require_relative "registry"
2
3
 
3
4
  module Relaton
@@ -6,11 +7,13 @@ module Relaton
6
7
  class Db
7
8
  SUPPORTED_GEMS = %w[ isobib rfcbib gbbib ].freeze
8
9
 
10
+ # @param global_cache [String] filename of global DB
11
+ # @param local_cache [String] filename of local DB
9
12
  def initialize(global_cache, local_cache)
10
- @bibdb = open_cache_biblio(global_cache)
11
- @local_bibdb = open_cache_biblio(local_cache)
12
- @bibdb_name = global_cache
13
- @local_bibdb_name = local_cache
13
+ @db = open_cache_biblio(global_cache)
14
+ @local_db = open_cache_biblio(local_cache)
15
+ @db_name = global_cache
16
+ @local_db_name = local_cache
14
17
  register_gems
15
18
  @registry = Relaton::Registry.instance
16
19
  end
@@ -38,11 +41,39 @@ module Relaton
38
41
  check_bibliocache(code, year, opts, stdclass)
39
42
  end
40
43
 
41
- def save
42
- save_cache_biblio(@bibdb, @bibdb_name)
43
- save_cache_biblio(@local_bibdb, @local_bibdb_name)
44
+ # @param key [String]
45
+ # @return [Hash]
46
+ def load_entry(key)
47
+ entry = @local_db.transaction { @local_db[key] }
48
+ return entry if entry
49
+ @db.transaction { @db[key] }
44
50
  end
45
51
 
52
+ # @param key [String]
53
+ # @param value [Hash]
54
+ # @option value [Date] "fetched"
55
+ # @option value [IsoBibItem::IsoBibliographicItem] "bib"
56
+ def save_entry(key, value)
57
+ @db.transaction { @db[key] = value }
58
+ @local_db.transaction { @local_db[key] = value }
59
+ end
60
+
61
+ # list all entris as a serialization
62
+ def to_xml
63
+ @db.transaction do
64
+ Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
65
+ xml.documents do
66
+ @db.roots.each { |key| @db[key]["bib"].to_xml(xml, {}) }
67
+ end
68
+ end.to_xml
69
+ end
70
+ end
71
+
72
+ # def save
73
+ # save_cache_biblio(@db, @db_name)
74
+ # save_cache_biblio(@local_db, @local_db_name)
75
+ # end
76
+
46
77
  private
47
78
 
48
79
  def standard_class(code)
@@ -52,10 +83,12 @@ module Relaton
52
83
  %r{^(ISO|IEC)[ /]|IEV($| )}.match? code and return :isobib
53
84
  =end
54
85
  @registry.processors.each do |name, processor|
55
- processor.prefix.match? code and return name
86
+ processor.prefix.match?(code) and return name
87
+ end
88
+ allowed = @registry.processors.reduce([]) do |m, (_k, v)|
89
+ m << v.prefix.inspect
56
90
  end
57
- warn "#{code} does not have a recognised prefix: "\
58
- "#{@registry.processors.inject([]) { |m, (k, v)| m << v.prefix.inspect }.join(', ')}"
91
+ warn "#{code} does not have a recognised prefix: #{allowed.join(', ')}"
59
92
  nil
60
93
  end
61
94
 
@@ -67,55 +100,69 @@ module Relaton
67
100
  ret
68
101
  end
69
102
 
103
+ # @param code [String]
104
+ # @param year [String]
105
+ # @param opts [Hash]
106
+ # @param stdclass [Symbol]
70
107
  def check_bibliocache(code, year, opts, stdclass)
71
108
  id = std_id(code, year, opts, stdclass)
72
- return nil if @bibdb.nil? # signals we will not be using isobib
73
- @bibdb[id] = nil unless is_valid_bibcache_entry?(@bibdb[id], year)
74
- @bibdb[id] ||= new_bibcache_entry(code, year, opts, stdclass)
75
- @local_bibdb[id] = @bibdb[id] if !@local_bibdb.nil? &&
76
- !is_valid_bibcache_entry?(@local_bibdb[id], year)
77
- return nil if @bibdb[id].nil?
78
- return @local_bibdb[id]["bib"] unless @local_bibdb.nil?
79
- @bibdb[id]["bib"]
109
+ return nil if @db.nil? # signals we will not be using isobib
110
+ @db.transaction do
111
+ @db.delete(id) unless valid_bib_entry?(@db[id], year)
112
+ @db[id] ||= new_bib_entry(code, year, opts, stdclass)
113
+ @local_db.transaction do
114
+ @local_db[id] = @db[id] if !valid_bib_entry?(@local_db[id], year)
115
+ @local_db[id]["bib"] == "not_found" ? nil : @local_db[id]["bib"]
116
+ end
117
+ end
80
118
  end
81
119
 
82
- # hash uses => , because the hash is imported from JSON
83
- def new_bibcache_entry(code, year, opts, stdclass)
120
+ # hash uses => , because the hash is imported from JSONo
121
+ # @param code [String]
122
+ # @param year [String]
123
+ # @param opts [Hash]
124
+ # @param stdclass [Symbol]
125
+ # @return [Hash]
126
+ def new_bib_entry(code, year, opts, stdclass)
84
127
  bib = @registry.processors[stdclass].get(code, year, opts)
85
- return nil if bib.nil?
128
+ bib = "not_found" if bib.nil?
86
129
  { "fetched" => Date.today, "bib" => bib }
87
130
  end
88
131
 
89
132
  # if cached reference is undated, expire it after 60 days
90
- def is_valid_bibcache_entry?(x, year)
91
- x && x.is_a?(Hash) && x&.has_key?("bib") && x&.has_key?("fetched") &&
92
- (year || Date.today - Date.iso8601(x["fetched"]) < 60)
133
+ # @param bib [Hash]
134
+ # @param year [String]
135
+ def valid_bib_entry?(bib, year)
136
+ bib&.is_a?(Hash) && bib&.has_key?("bib") && bib&.has_key?("fetched") &&
137
+ (year || Date.today - bib["fetched"] < 60)
93
138
  end
94
139
 
140
+ # @param filename [String] DB filename
141
+ # @return [Hash]
95
142
  def open_cache_biblio(filename)
96
- biblio = {}
97
- return {} unless !filename.nil? && Pathname.new(filename).file?
98
- File.open(filename, "r") { |f| biblio = JSON.parse(f.read) }
99
- biblio.each do |k, v|
100
- biblio[k]&.fetch("bib") and
101
- biblio[k]["bib"] = from_xml(biblio[k]["bib"])
102
- end
103
- biblio
143
+ PStore.new filename
144
+ # biblio = {}
145
+ # return {} unless !filename.nil? && Pathname.new(filename).file?
146
+ # File.open(filename, "r") { |f| biblio = JSON.parse(f.read) }
147
+ # biblio.each { |_k, v| v["bib"] && (v["bib"] = from_xml(v["bib"])) }
148
+ # biblio
104
149
  end
105
150
 
106
- def from_xml(entry)
107
- entry # will be unmarshaller
108
- end
151
+ # @param enstry [String] entry in XML format
152
+ # @return [IsoBibItem::IsoBibliographicItem]
153
+ # def from_xml(entry)
154
+ # IsoBibItem.from_xml entry # will be unmarshaller
155
+ # end
109
156
 
110
- def save_cache_biblio(biblio, filename)
111
- return if biblio.nil? || filename.nil?
112
- biblio.each do |k, v|
113
- biblio[k]&.fetch("bib")&.respond_to? :to_xml and
114
- biblio[k]["bib"] = biblio[k]["bib"].to_xml
115
- end
116
- File.open(filename, "w") do |b|
117
- b << biblio.to_json
118
- end
119
- end
157
+ # @param [Hash{String=>Hash{String=>String}}] biblio
158
+ # def save_cache_biblio(biblio, filename)
159
+ # return if biblio.nil? || filename.nil?
160
+ # File.open(filename, "w") do |b|
161
+ # b << biblio.reduce({}) do |s, (k, v)|
162
+ # bib = v["bib"].respond_to?(:to_xml) ? v["bib"].to_xml : v["bib"]
163
+ # s.merge(k => { "fetched" => v["fetched"], "bib" => bib })
164
+ # end.to_json
165
+ # end
166
+ # end
120
167
  end
121
168
  end