relaton 0.3.4 → 0.4.0

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: 0fc173e172f5bce023b95d084eb5ea993e956e1db7528d62a03573c9043b3dfd
4
- data.tar.gz: 41467a22d7174a6dcbe76cf4ac85c3d7123be298f034ad85429219e722df96c8
3
+ metadata.gz: 00f79ee6d4b4884984fe6749a60932b026822a6355416f7620c06dbb0bc3f4e7
4
+ data.tar.gz: 6cd7711482a8e44df75b278b6e0c5f19e7de48319e8cd4949c121e6ca5d8055f
5
5
  SHA512:
6
- metadata.gz: 221238fd7ab1b8c83d85c6e954fe2598bd6bd43354572b3d5a67c70d79a67f1e6ff65b7210c4d05303517dcf43ed4bed455530bbb5ffd96abf3ce65c4f1827da
7
- data.tar.gz: 308dfe38a070836311eca5911d77e2b6cd289f8fe4ffd5c2e20324457ef2ae16b899e88853e82f64800a638b0eaac7b68d80f5e6a48ff5cfbf52bc4c61bb81f5
6
+ metadata.gz: cb0a9e93a381597c95513a6966d6795822dd0eca1f3fa903de22218416570ebc41f9424082bf3f79423a6e2fa23b387d34e40bb9df822118e4a2c719a7a06751
7
+ data.tar.gz: fd679aacb503d9ec7ee0b6483048dda5de8fcf203a2ffd45d1f376f1fc37bf82896bc735f467579f7283ef6bae9abe2529269505ca8eef551fc968e4c95e3b71
data/.gitignore CHANGED
@@ -3,4 +3,8 @@ coverage/
3
3
  .rspec_status
4
4
 
5
5
  testcache
6
- testcache2
6
+ testcache2
7
+ globalcahe/
8
+ localcahe/
9
+ .rubocop-https---raw-githubusercontent-com-riboseinc-oss-guides-master-ci-rubocop-yml
10
+ .vscode/
@@ -1,3 +1,5 @@
1
+ # Auto-generated !!! Do not edit it manually
2
+ # use ci-master https://github.com/metanorma/metanorma-build-scripts
1
3
  language: ruby
2
4
  cache: bundler
3
5
  os:
@@ -6,12 +8,10 @@ os:
6
8
  rvm:
7
9
  - 2.5
8
10
  - 2.4
9
- - 2.3
10
11
  - ruby-head
11
- before_install:
12
+ before_install:
12
13
  - gem install bundler -v 2.0.1
13
14
  - bundle update
14
15
  matrix:
15
16
  allow_failures:
16
17
  - rvm: ruby-head
17
-
@@ -1,14 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- relaton (0.3.4)
4
+ relaton (0.4.0)
5
5
  algoliasearch
6
- gbbib (~> 0.4.0)
7
- iecbib (~> 0.2.0)
8
- ietfbib (~> 0.4.2)
9
- iso-bib-item (~> 0.4.2)
10
- isobib (~> 0.4.0)
11
- nistbib (~> 0.1.1)
6
+ relaton-gb (~> 0.5.0)
7
+ relaton-iec (~> 0.3.0)
8
+ relaton-ietf (~> 0.5.0)
9
+ relaton-iso (~> 0.5.0)
10
+ relaton-iso-bib (~> 0.2.0)
11
+ relaton-itu (~> 0.2.0)
12
+ relaton-nist (~> 0.2.0)
12
13
 
13
14
  GEM
14
15
  remote: https://rubygems.org/
@@ -24,17 +25,16 @@ GEM
24
25
  coderay (1.1.2)
25
26
  crack (0.4.3)
26
27
  safe_yaml (~> 1.0.0)
28
+ debase (0.2.2)
29
+ debase-ruby_core_source (>= 0.10.2)
30
+ debase-ruby_core_source (0.10.5)
27
31
  diff-lcs (1.3)
28
- docile (1.3.1)
32
+ docile (1.3.2)
29
33
  equivalent-xml (0.6.0)
30
34
  nokogiri (>= 1.4.3)
31
- ffi (1.10.0)
35
+ ffi (1.11.1)
32
36
  formatador (0.2.5)
33
37
  gb-agencies (0.0.5)
34
- gbbib (0.4.4)
35
- cnccs (~> 0.1.1)
36
- gb-agencies (~> 0.0.1)
37
- iso-bib-item (~> 0.4.2)
38
38
  guard (2.15.0)
39
39
  formatador (>= 0.2.4)
40
40
  listen (>= 2.7, < 4.0)
@@ -49,21 +49,8 @@ GEM
49
49
  guard (~> 2.1)
50
50
  guard-compat (~> 1.1)
51
51
  rspec (>= 2.99.0, < 4.0)
52
- hashdiff (0.3.8)
52
+ hashdiff (0.4.0)
53
53
  httpclient (2.8.3)
54
- iecbib (0.2.2)
55
- addressable
56
- iso-bib-item (~> 0.4.2)
57
- ietfbib (0.4.5)
58
- iso-bib-item (~> 0.4.2)
59
- iso-bib-item (0.4.5)
60
- isoics (~> 0.1.6)
61
- nokogiri (~> 1.8.4)
62
- ruby_deep_clone (~> 0.8.0)
63
- isobib (0.4.4)
64
- algoliasearch
65
- iecbib (~> 0.2.1)
66
- iso-bib-item (~> 0.4.2)
67
54
  isoics (0.1.7)
68
55
  json (2.2.0)
69
56
  listen (3.1.5)
@@ -74,15 +61,13 @@ GEM
74
61
  method_source (0.9.2)
75
62
  mini_portile2 (2.3.0)
76
63
  nenv (0.3.0)
77
- nistbib (0.1.1)
78
- iso-bib-item (~> 0.4.2)
79
64
  nokogiri (1.8.5)
80
65
  mini_portile2 (~> 2.3.0)
81
66
  notiffany (0.1.1)
82
67
  nenv (~> 0.1)
83
68
  shellany (~> 0.0)
84
69
  parallel (1.17.0)
85
- parser (2.6.2.1)
70
+ parser (2.6.3.0)
86
71
  ast (~> 2.4.0)
87
72
  powerpack (0.1.2)
88
73
  pry (0.12.2)
@@ -91,25 +76,50 @@ GEM
91
76
  pry-byebug (3.6.0)
92
77
  byebug (~> 10.0)
93
78
  pry (~> 0.10)
94
- public_suffix (3.0.3)
79
+ public_suffix (3.1.0)
95
80
  rainbow (3.0.0)
96
81
  rake (12.3.2)
97
82
  rb-fsevent (0.10.3)
98
83
  rb-inotify (0.10.0)
99
84
  ffi (~> 1.0)
85
+ relaton-bib (0.2.0)
86
+ addressable
87
+ nokogiri (~> 1.8.4)
88
+ relaton-gb (0.5.0)
89
+ cnccs (~> 0.1.1)
90
+ gb-agencies (~> 0.0.1)
91
+ relaton-iso-bib (~> 0.2.0)
92
+ relaton-iec (0.3.0)
93
+ addressable
94
+ relaton-iso-bib (~> 0.2.0)
95
+ relaton-ietf (0.5.0)
96
+ relaton-iso-bib (~> 0.2.0)
97
+ relaton-iso (0.5.0)
98
+ algoliasearch
99
+ relaton-iec (~> 0.3.0)
100
+ relaton-iso-bib (~> 0.2.0)
101
+ relaton-iso-bib (0.2.0)
102
+ isoics (~> 0.1.6)
103
+ nokogiri (~> 1.8.4)
104
+ relaton-bib (~> 0.2.0)
105
+ ruby_deep_clone (~> 0.8.0)
106
+ relaton-itu (0.2.0)
107
+ relaton-iso-bib (~> 0.2.0)
108
+ relaton-nist (0.2.0)
109
+ relaton-bib (~> 0.2.0)
100
110
  rspec (3.8.0)
101
111
  rspec-core (~> 3.8.0)
102
112
  rspec-expectations (~> 3.8.0)
103
113
  rspec-mocks (~> 3.8.0)
104
- rspec-core (3.8.0)
114
+ rspec-core (3.8.1)
105
115
  rspec-support (~> 3.8.0)
106
- rspec-expectations (3.8.2)
116
+ rspec-expectations (3.8.4)
107
117
  diff-lcs (>= 1.2.0, < 2.0)
108
118
  rspec-support (~> 3.8.0)
109
- rspec-mocks (3.8.0)
119
+ rspec-mocks (3.8.1)
110
120
  diff-lcs (>= 1.2.0, < 2.0)
111
121
  rspec-support (~> 3.8.0)
112
- rspec-support (3.8.0)
122
+ rspec-support (3.8.2)
113
123
  rubocop (0.54.0)
114
124
  parallel (~> 1.10)
115
125
  parser (>= 2.5)
@@ -117,7 +127,9 @@ GEM
117
127
  rainbow (>= 2.2.2, < 4.0)
118
128
  ruby-progressbar (~> 1.7)
119
129
  unicode-display_width (~> 1.0, >= 1.0.1)
120
- ruby-progressbar (1.10.0)
130
+ ruby-debug-ide (0.7.0)
131
+ rake (>= 0.8.1)
132
+ ruby-progressbar (1.10.1)
121
133
  ruby_deep_clone (0.8.0)
122
134
  ruby_dep (1.5.0)
123
135
  safe_yaml (1.0.5)
@@ -129,12 +141,12 @@ GEM
129
141
  simplecov-html (0.10.2)
130
142
  thor (0.20.3)
131
143
  timecop (0.9.1)
132
- unicode-display_width (1.5.0)
133
- vcr (4.0.0)
134
- webmock (3.5.1)
144
+ unicode-display_width (1.6.0)
145
+ vcr (5.0.0)
146
+ webmock (3.6.0)
135
147
  addressable (>= 2.3.6)
136
148
  crack (>= 0.3.2)
137
- hashdiff
149
+ hashdiff (>= 0.4.0, < 2.0.0)
138
150
 
139
151
  PLATFORMS
140
152
  ruby
@@ -142,6 +154,7 @@ PLATFORMS
142
154
  DEPENDENCIES
143
155
  bundler (~> 2.0.1)
144
156
  byebug (~> 10.0)
157
+ debase
145
158
  equivalent-xml (~> 0.6)
146
159
  guard (~> 2.14)
147
160
  guard-rspec (~> 4.7)
@@ -150,6 +163,7 @@ DEPENDENCIES
150
163
  relaton!
151
164
  rspec (~> 3.6)
152
165
  rubocop (= 0.54.0)
166
+ ruby-debug-ide
153
167
  simplecov (~> 0.15)
154
168
  timecop (~> 0.9)
155
169
  vcr
@@ -1,10 +1,14 @@
1
+ # Auto-generated !!! Do not edit it manually
2
+ # use ci-master https://github.com/metanorma/metanorma-build-scripts
1
3
  version: '{build}'
2
4
 
5
+ cache:
6
+ - vendor/bundle
7
+
3
8
  environment:
4
9
  matrix:
5
10
  - RUBY_VERSION: 25
6
11
  - RUBY_VERSION: 24
7
- - RUBY_VERSION: 23
8
12
  - RUBY_VERSION: _trunk
9
13
 
10
14
  matrix:
@@ -17,6 +21,8 @@ install:
17
21
 
18
22
  build_script:
19
23
  - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
24
+ - set GIT_TERMINAL_PROMPT=0
25
+ - bundle config --local path vendor/bundle
20
26
  - bundle update
21
27
  - bundle install
22
28
 
@@ -27,4 +33,3 @@ before_test:
27
33
 
28
34
  test_script:
29
35
  - bundle exec rake
30
-
@@ -19,15 +19,16 @@ Entries are serialised to and from an internal data model, and multiple formats
19
19
 
20
20
  Relaton imports bibliographic entries from:
21
21
 
22
- * ISO through the iso.org website, via the https://github.com/metanorma/isobib[isobib] gem
23
- * IEC through the iec.ch website, via the https://github.com/metanorma/iecbib[isobib] gem
24
- * GB (Chinese national standards) through the GB websites, via the https://github.com/metanorma/gbbib[gbbib] gem
25
- * IETF standards (Internet Drafts, RFC) through the http://xml2rfc.tools.ietf.org website, via the https://github.com/metanorma/ietfbib[ietfbib] gem
22
+ * ISO through the iso.org website, via the https://github.com/metanorma/relaton-iso[relaton-iso] gem
23
+ * IEC through the iec.ch website, via the https://github.com/metanorma/relaton-iec[relaton-iec] gem
24
+ * GB (Chinese national standards) through the GB websites, via the https://github.com/metanorma/relaton-gb[relaton-gb] gem
25
+ * IETF standards (Internet Drafts, RFC) through the http://xml2rfc.tools.ietf.org website, via the https://github.com/metanorma/relaton-ietf[relaton-ietf] gem
26
+ * NIST standards through the nist.gov website, via the https://github.com/metanorma/relaton-nist[relaotn-nist] gem
26
27
 
27
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:
28
29
 
29
- * If the standards body is national, the wrapper uses the ISO country code. So `CN(GM/T 0009-2012)` is Chinese sector standard GM/T 0009-2012.
30
- * If the standards body is international, the wrappers uses the agreed abbreviation of the standards body. So `IETF(I-D.ribose-asciirfc-08)` identifiers `I-D.ribose-asciirfc` as an Internet Engineering Task Force identifier.
30
+ * If the standards body is the national standards body, the wrapper uses the ISO country code. So `CN(GM/T 0009-2012)` is Chinese sector standard GM/T 0009-2012.
31
+ * Otherwise, the wrappers uses the agreed abbreviation of the standards body. So `IETF(I-D.ribose-asciirfc-08)` identifies `I-D.ribose-asciirfc` as an Internet Engineering Task Force identifier.
31
32
  * Some prefixes to identifiers indicate the standards body they belong to unambiguously; e.g. `ISO` followed by slash or space. The scope wrapper is not required for those prefixes: `ISO(ISO 639-1)` can be recognised as just `ISO 639-1`.
32
33
 
33
34
  The gem can be extended to use other standards-specific gems. Standards-specific gems like isobib register themselves against Relaton using `Relaton::Registry.instance.register`, which takes as an argument a subclass of `Relaton::Processor` defined in the gem; see isobib/lib/relaton for an example. The processor within the standards-specific gem needs to define
@@ -65,44 +66,62 @@ require "relaton"
65
66
 
66
67
  # Do not cache any entries retrieved
67
68
  db = Relaton::Db.new(nil, nil)
69
+ [relaton] Info: detecting backends:
70
+ [relaton] processor "relaton_iec" registered
71
+ [relaton] processor "relaton_iso" registered
72
+ [relaton] processor "relaton_ietf" registered
73
+ [relaton] processor "relaton_gb" registered
74
+ [relaton] processor "relaton_nist" registered
75
+ => #<Relaton::Db:0x007fb1d2a75fe0
76
+ ...
68
77
 
69
78
  # Use only the global cache for any entries retrieved
70
- db = Relaton::Db.new("global cache filename", nil)
79
+ db = Relaton::Db.new("globalcache", nil)
80
+ [relaton] Info: detecting backends:
81
+ => #<Relaton::Db:0x007fb1d2856fc0
82
+ ...
71
83
 
72
84
  # Use both a local and a global cache
73
- db = Relaton::Db.new("global cache filename", "local cache filename")
74
- [relaton] detecting backends:
75
- isobib
76
- [relaton] processor "isobib" registered
77
- => #<Relaton::Db:...>
85
+ db = Relaton::Db.new("globalcahe", "localcahe")
86
+ [relaton] Info: detecting backends:
87
+ => #<Relaton::Db:0x007fb1d0ab9328
88
+ ...
78
89
 
79
90
  x = db.fetch("IEEE 19011")
80
- "IEEE 19011 does not have a recognised prefix: /^(ISO|IEC)[ \/]|^IEV($| )/"
91
+ IEEE 19011 does not have a recognised prefix: IEC, ISO, IETF, CN, NIST
81
92
  => nil
82
93
 
83
94
  x = db.fetch("ISO 19011")
84
95
  fetching ISO 19011...
85
- => #<IsoBibItem::IsoBibliographicItem:...>
96
+ => #<RelatonIsoBib::IsoBibliographicItem:0x007fb1d0ab2f00
97
+ ...
86
98
 
87
99
  x = db.fetch("ISO 19011", "2011")
88
100
  fetching ISO 19011...
89
- => #<IsoBibItem::IsoBibliographicItem:...>
101
+ => #<RelatonIsoBib::IsoBibliographicItem:0x007fb1d2593068
102
+ ...
90
103
 
91
104
  x = db.fetch("ISO 19011", "2011", allparts: true)
92
- fetching ISO 19011...
93
- => #<IsoBibItem::IsoBibliographicItem:...>
105
+ => #<RelatonIsoBib::IsoBibliographicItem:0x007fb1d0ae8bf0
106
+ ...
94
107
 
95
- x = db.docid_type("CN(GB/T 1.1)")
108
+ db.docid_type("CN(GB/T 1.1)")
96
109
  => ["Chinese Standard", "GB/T 1.1"]
97
110
 
98
111
  x.to_xml
99
- => "<bib-item type=\"international-standard\" id=\"ISO19011\">...."
112
+ => "<bibitem id="ISO19011-2011">...."
100
113
 
101
114
  db.to_xml
102
- => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<documents>\n <bibitem type=\"international-standard\"...."
115
+ => "<?xml version\"1.0" encoding="UTF-8"?><documents><bibdata>...."
116
+
117
+ x.to_xml
118
+ => "<bibitem id="ISO19011-2011">..."
119
+
120
+ x.to_xml
121
+ => "<bibdata>..."
103
122
 
104
123
  db.load_entry("ISO(ISO 19011)")
105
- => #<IsoBibItem::IsoBibliographicItem:...>
124
+ => "<bibdata>..."
106
125
 
107
126
  db.save_entry("ISO(ISO 19011)", nil)
108
127
  => nil
@@ -1,4 +1,5 @@
1
1
  require_relative "relaton/db"
2
+ require_relative "relaton/db_cache"
2
3
  require_relative "relaton/version"
3
4
  require_relative "relaton/registry"
4
5
  require_relative "relaton/processor"
@@ -1,12 +1,12 @@
1
1
  # require "pstore"
2
2
  require_relative "registry"
3
- require_relative 'db_cache'
3
+ require_relative "db_cache"
4
4
 
5
5
  module Relaton
6
6
  class RelatonError < StandardError; end
7
7
 
8
8
  class Db
9
- SUPPORTED_GEMS = %w[isobib ietfbib gbbib iecbib nistbib].freeze
9
+ SUPPORTED_GEMS = %w[relaton_iso relaton_ietf relaton_gb relaton_iec relaton_nist].freeze
10
10
 
11
11
  # @param global_cache [String] directory of global DB
12
12
  # @param local_cache [String] directory of local DB
@@ -42,28 +42,28 @@ module Relaton
42
42
  check_bibliocache(code, year, opts, stdclass)
43
43
  end
44
44
 
45
- def fetch_std(code, year = nil, stdclass = nil, opts = {})
46
- std = nil
47
- @registry.processors.each do |name, processor|
48
- std = name if processor.prefix == stdclass
49
- end
50
- unless std
51
- std = standard_class(code) or return nil
52
- end
53
- check_bibliocache(code, year, opts, std)
54
- end
45
+ # def fetch_std(code, year = nil, stdclass = nil, opts = {})
46
+ # std = nil
47
+ # @registry.processors.each do |name, processor|
48
+ # std = name if processor.prefix == stdclass
49
+ # end
50
+ # unless std
51
+ # std = standard_class(code) or return nil
52
+ # end
53
+ # check_bibliocache(code, year, opts, std)
54
+ # end
55
55
 
56
- def fetched(key)
57
- return @local_db.fetched key if @local_db
58
- return @db.fetched key if @db
56
+ # def fetched(key)
57
+ # return @local_db.fetched key if @local_db
58
+ # return @db.fetched key if @db
59
59
 
60
- ""
61
- end
60
+ # ""
61
+ # end
62
62
 
63
63
  # The document identifier class corresponding to the given code
64
64
  def docid_type(code)
65
65
  stdclass = standard_class(code) or return [nil, code]
66
- prefix, code = strip_id_wrapper(code, stdclass)
66
+ _prefix, code = strip_id_wrapper(code, stdclass)
67
67
  [@registry.processors[stdclass].idtype, code]
68
68
  end
69
69
 
@@ -103,7 +103,7 @@ module Relaton
103
103
  def standard_class(code)
104
104
  @registry.processors.each do |name, processor|
105
105
  return name if /^#{processor.prefix}/.match(code) ||
106
- processor.defaultprefix.match(code)
106
+ processor.defaultprefix.match(code)
107
107
  end
108
108
  allowed = @registry.processors.reduce([]) do |m, (_k, v)|
109
109
  m << v.prefix
@@ -170,7 +170,7 @@ module Relaton
170
170
  # @return [Hash]
171
171
  def new_bib_entry(code, year, opts, stdclass)
172
172
  bib = @registry.processors[stdclass].get(code, year, opts)
173
- bib = bib.to_xml if bib.respond_to? :to_xml
173
+ bib = bib.to_xml(bibdata: true) if bib.respond_to? :to_xml
174
174
  bib = "not_found #{Date.today}" if bib.nil? || bib.empty?
175
175
  bib
176
176
  end
@@ -188,21 +188,22 @@ module Relaton
188
188
  # @return [PStore]
189
189
  def open_cache_biblio(dir, global: true)
190
190
  return nil if dir.nil?
191
+
191
192
  db = DbCache.new dir
192
- if File.exist? dir
193
- if global
194
- unless db.check_version?
195
- FileUtils.rm_rf(Dir.glob(dir + '/*'), secure: true)
196
- warn "Global cache version is obsolete and cleared."
197
- end
198
- db.set_version
199
- elsif db.check_version? then db
200
- else
201
- warn "Local cache version is obsolete."
202
- nil
193
+ # if File.exist? dir
194
+ if global
195
+ unless db.check_version?
196
+ FileUtils.rm_rf(Dir.glob(dir + "/*"), secure: true)
197
+ warn "Global cache version is obsolete and cleared."
203
198
  end
204
- else db.set_version
199
+ db.set_version
200
+ elsif db.check_version? then db
201
+ else
202
+ warn "Local cache version is obsolete."
203
+ nil
205
204
  end
205
+ # else db.set_version
206
+ # end
206
207
  end
207
208
 
208
209
  # Check if version of the DB match to the gem version.