relaton 0.1.6 → 0.2.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: 461a1144fc2a8bcad638809bba2487dc86a28e0ec7faacd552a63c81228ac109
4
- data.tar.gz: b87e444bdbbd5a16ae12269fa9feb2fecb957175f1fffc29b4959944ee523e83
3
+ metadata.gz: 33f253d144e0c65c1566fbca9cf1ed1091bc3cbc45684ba6018ed55931b74bf2
4
+ data.tar.gz: 45512a29a7ca17f7163d6b1ad638b24f27362bf664d36b46e8d46ca1e18d189d
5
5
  SHA512:
6
- metadata.gz: 22f6aa0825ee61196b772b6a225711fd2164110f89135ae2f3922ed88f4db3230eea7221cf3324bee869708176919a3cf6b01117b309b4a80b9e63c1ffc57ab4
7
- data.tar.gz: 44d21285d3569156d2364eadab4c42781c88c95cbbd2f1220e5b988a26d6212496a8b61013e53ca745755859119ee9d6c59ceb43bf55771a48185bbb508feb0e
6
+ metadata.gz: f0faf8d0629d94b8903ffb8bccc8b6a136a15845c7deaeabeb25a95a8ede5fb8290b37d40dd5d8eaf5d7eb0819452f859f653d4f232e8c9d7fa4879e3cd0770e
7
+ data.tar.gz: a8016b0c497a30e2f2af7d82d1f6ffe47114ace623ad825fd5654ead94591d7cb4cb7daedd5be4cb4a5e991d3c35f9534552ce75848e9007039420b861033afd
data/Gemfile.lock CHANGED
@@ -1,12 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- relaton (0.1.6)
4
+ relaton (0.2.0)
5
5
  algoliasearch
6
- gbbib (~> 0.2.1)
7
- iso-bib-item (~> 0.2.3)
8
- isobib (~> 0.2.0)
9
- rfcbib (~> 0.2.2)
6
+ gbbib (~> 0.3.0)
7
+ iso-bib-item (~> 0.3.0)
8
+ isobib (~> 0.3.0)
9
+ rfcbib (~> 0.3.0)
10
10
 
11
11
  GEM
12
12
  remote: https://rubygems.org/
@@ -15,7 +15,7 @@ GEM
15
15
  httpclient (~> 2.8, >= 2.8.3)
16
16
  json (>= 1.5.1)
17
17
  ast (2.4.0)
18
- byebug (9.1.0)
18
+ byebug (10.0.2)
19
19
  cnccs (0.1.3)
20
20
  coderay (1.1.2)
21
21
  diff-lcs (1.3)
@@ -25,10 +25,10 @@ GEM
25
25
  ffi (1.9.25)
26
26
  formatador (0.2.5)
27
27
  gb-agencies (0.0.3)
28
- gbbib (0.2.3)
28
+ gbbib (0.3.0)
29
29
  cnccs (~> 0.1.1)
30
30
  gb-agencies (~> 0.0.1)
31
- iso-bib-item (~> 0.2)
31
+ iso-bib-item (~> 0.3.0)
32
32
  guard (2.14.2)
33
33
  formatador (>= 0.2.4)
34
34
  listen (>= 2.7, < 4.0)
@@ -44,13 +44,13 @@ GEM
44
44
  guard-compat (~> 1.1)
45
45
  rspec (>= 2.99.0, < 4.0)
46
46
  httpclient (2.8.3)
47
- iso-bib-item (0.2.5)
47
+ iso-bib-item (0.3.0)
48
48
  isoics (~> 0.1.6)
49
49
  nokogiri (~> 1.8.4)
50
50
  ruby_deep_clone (~> 0.8.0)
51
- isobib (0.2.5)
51
+ isobib (0.3.0)
52
52
  algoliasearch
53
- iso-bib-item (~> 0.2.4)
53
+ iso-bib-item (~> 0.3.0)
54
54
  isoics (0.1.7)
55
55
  jaro_winkler (1.5.1)
56
56
  json (2.1.0)
@@ -74,16 +74,16 @@ GEM
74
74
  pry (0.11.3)
75
75
  coderay (~> 1.1.0)
76
76
  method_source (~> 0.9.0)
77
- pry-byebug (3.5.1)
78
- byebug (~> 9.1)
77
+ pry-byebug (3.6.0)
78
+ byebug (~> 10.0)
79
79
  pry (~> 0.10)
80
80
  rainbow (3.0.0)
81
81
  rake (12.3.1)
82
82
  rb-fsevent (0.10.3)
83
83
  rb-inotify (0.9.10)
84
84
  ffi (>= 0.5.0, < 2)
85
- rfcbib (0.2.2)
86
- iso-bib-item (~> 0.2.0)
85
+ rfcbib (0.3.0)
86
+ iso-bib-item (~> 0.3.0)
87
87
  rspec (3.8.0)
88
88
  rspec-core (~> 3.8.0)
89
89
  rspec-expectations (~> 3.8.0)
@@ -123,7 +123,7 @@ PLATFORMS
123
123
 
124
124
  DEPENDENCIES
125
125
  bundler (~> 1.15)
126
- byebug (~> 9.1)
126
+ byebug (~> 10.0)
127
127
  equivalent-xml (~> 0.6)
128
128
  guard (~> 2.14)
129
129
  guard-rspec (~> 4.7)
data/README.adoc CHANGED
@@ -18,14 +18,20 @@ Entries are serialised to and from an internal data model, and multiple formats
18
18
 
19
19
  Relaton imports bibliographic entries from:
20
20
 
21
- * ISO and IEC through the iso.org website, via the https://github.com/riboseinc/isobib[isobib] gem
22
- * GB (Chinese national standards) through the GB websites, via the https://github.com/riboseinc/gbbib[gbbib] gem [in progress]
23
- * IETF standards (Internet Drafts, RFC) through the http://xml2rfc.tools.ietf.org website, via the https://github.com/riboseinc/rfcbib[rfcbib] gem [in progress]
21
+ * ISO through the iso.org website, via the https://github.com/riboseinc/isobib[isobib] gem
22
+ * GB (Chinese national standards) through the GB websites, via the https://github.com/riboseinc/gbbib[gbbib] gem
23
+ * IETF standards (Internet Drafts, RFC) through the http://xml2rfc.tools.ietf.org website, via the https://github.com/riboseinc/rfcbib[rfcbib] gem
24
+
25
+ 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:
26
+ * 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.
27
+ * 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.
28
+ * 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`.
24
29
 
25
30
  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
26
31
 
27
32
  * `@short`, the name of the gem
28
- * `@prefix`, the regex constraining the standards code to be processed
33
+ * `@prefix`, the regex which scopes the identifier, and constrains it to belong to a particular standards class.
34
+ * `@defaultprefix`, the identifier prefixes which can be recognised without a scope wrapper.
29
35
  * `get(code, date, opts)`, which takes a standards code, a year, and a hash of options, and returns an iso-bib-item bibliographic entry
30
36
  ** `date == nil`: an ISO reference is treated as a generic reference to the latest available version of the reference. The latest
31
37
  version retrieved has its date of publicatipn stripped. The dated reference is retained as an `instanceOf` relation to the reference.
@@ -39,15 +45,12 @@ e.g. `get("ISO 19115-1", "2014", all_parts: true)` is transformed into a referen
39
45
 
40
46
  == Behaviours
41
47
 
42
- * Bibliographic entries are identified for retrieval and caching by a prefix specific to the standards class, followed by the conventional code of the standard.
43
- ** ISO standards are identified by `ISO` followed by space or slash. For example, `ISO/IEC DIR 2:2018`
44
- ** IEC standards are identified by `IEC` followed by space or slash
45
- ** GB standards are identified by `GB Standard`. For example, `GB Standard GM/T 0009-2012`
46
- ** IETF stadnards are identified by `IETF`. Foe example, `IETF RFC 7991`
47
48
  * If an entry is defined in both the local and the global cache, the local cache entry is used.
48
49
  * If an ISO entry has no date, the latest version available for the entry is retrieved.
49
50
  * If a cached ISO entry has no date, and was last retrieved more than 60 days ago, the gem fetches it again, in case there is a newer edition of the standard available.
51
+ * Entries are always saved to the cache with a scope-wrapped identifier; e.g. under `ISO(ISO 639-1)`, and not `ISO 639-1`.
50
52
  * Note that the gem does not currently support the totality of the Relaton model; it will only support the information available in the source websites. We do not expect to support cartographic information, for example.
53
+ * Document identifiers are returned with a scope indication; for example, `<docidentifier type="IETF">RFC 8000</docidentifier>`. It is up to the client whether to render this with the scope indication (_IETF RFC 8000_) or without (_RFC 8000_).
51
54
 
52
55
  == Usage
53
56
 
@@ -89,13 +92,13 @@ x.to_xml
89
92
  db.to_xml
90
93
  => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<documents>\n <bibitem type=\"international-standard\"...."
91
94
 
92
- db.load_entry("ISO 19011")
95
+ db.load_entry("ISO(ISO 19011)")
93
96
  => #<IsoBibItem::IsoBibliographicItem:...>
94
97
 
95
- db.save_entry("ISO 19011", nil)
98
+ db.save_entry("ISO(ISO 19011)", nil)
96
99
  => nil
97
100
 
98
- db.load_entry("ISO 19011")
101
+ db.load_entry("ISO(ISO 19011)")
99
102
  => nil
100
103
 
101
104
  ----
data/lib/relaton/db.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require "pstore"
2
- # require "iso_bib_item"
3
2
  require_relative "registry"
4
3
 
5
4
  module Relaton
@@ -78,22 +77,24 @@ module Relaton
78
77
 
79
78
  def standard_class(code)
80
79
  @registry.processors.each do |name, processor|
81
- return name if processor.prefix.match(code)
80
+ return name if /#{processor.prefix}/.match(code) ||
81
+ processor.defaultprefix.match(code)
82
82
  end
83
83
  allowed = @registry.processors.reduce([]) do |m, (_k, v)|
84
- m << v.prefix.inspect
84
+ m << v.prefix
85
85
  end
86
86
  warn "#{code} does not have a recognised prefix: #{allowed.join(', ')}"
87
87
  nil
88
88
  end
89
89
 
90
90
  # TODO: i18n
91
- def std_id(code, year, opts, _stdclass)
91
+ def std_id(code, year, opts, stdclass)
92
+ prefix = @registry.processors[stdclass].prefix
93
+ code = code.sub(/^#{prefix}\((.+)\)$/, "\\1")
92
94
  ret = code
93
95
  ret += ":#{year}" if year
94
96
  ret += " (all parts)" if opts[:all_parts]
95
- code = code.sub(/^(GB Standard|IETF( Standard)?) /, "")
96
- [ret, code]
97
+ ["#{prefix}(#{ret})", code]
97
98
  end
98
99
 
99
100
  def bib_retval(entry)
@@ -3,6 +3,7 @@ module Relaton
3
3
 
4
4
  attr_reader :short
5
5
  attr_reader :prefix
6
+ attr_reader :defaultprefix
6
7
 
7
8
  def initialize
8
9
  raise "This is an abstract class!"
@@ -1,3 +1,3 @@
1
1
  module Relaton
2
- VERSION = "0.1.6".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
data/relaton.gemspec CHANGED
@@ -28,13 +28,13 @@ Gem::Specification.new do |spec|
28
28
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
29
29
 
30
30
  spec.add_dependency "algoliasearch"
31
- spec.add_dependency "gbbib", "~> 0.2.1"
32
- spec.add_dependency "isobib", "~> 0.2.0"
33
- spec.add_dependency "rfcbib", "~> 0.2.2"
34
- spec.add_dependency 'iso-bib-item', '~> 0.2.3'
31
+ spec.add_dependency "gbbib", "~> 0.3.0"
32
+ spec.add_dependency "isobib", "~> 0.3.0"
33
+ spec.add_dependency "rfcbib", "~> 0.3.0"
34
+ spec.add_dependency 'iso-bib-item', '~> 0.3.0'
35
35
 
36
36
  spec.add_development_dependency "bundler", "~> 1.15"
37
- spec.add_development_dependency "byebug", "~> 9.1"
37
+ spec.add_development_dependency "byebug", "~> 10.0"
38
38
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
39
39
  spec.add_development_dependency "guard", "~> 2.14"
40
40
  spec.add_development_dependency "guard-rspec", "~> 4.7"
@@ -29,11 +29,11 @@ RSpec.describe Relaton::Db do
29
29
  expect(File.exist?("testcache2")).to be true
30
30
  testcache = PStore.new "testcache"
31
31
  testcache.transaction true do
32
- expect(testcache["ISO 19115-1"]["bib"].to_xml).to include "<bibitem type=\"international-standard\" id=\"ISO19115-1\">"
32
+ expect(testcache["ISO(ISO 19115-1)"]["bib"].to_xml).to include "<bibitem type=\"international-standard\" id=\"ISO19115-1\">"
33
33
  end
34
34
  testcache = PStore.new "testcache2"
35
35
  testcache.transaction do
36
- expect(testcache["ISO 19115-1"]["bib"].to_xml).to include "<bibitem type=\"international-standard\" id=\"ISO19115-1\">"
36
+ expect(testcache["ISO(ISO 19115-1)"]["bib"].to_xml).to include "<bibitem type=\"international-standard\" id=\"ISO19115-1\">"
37
37
  end
38
38
  end
39
39
 
@@ -45,13 +45,13 @@ RSpec.describe Relaton::Db do
45
45
  expect(File.exist?("testcache2")).to be true
46
46
  testcache = PStore.new "testcache"
47
47
  testcache.transaction do
48
- expect(testcache["ISO 111111119115-1"]["fetched"].to_s).to eq Date.today.to_s
49
- expect(testcache["ISO 111111119115-1"]["bib"]).to eq "not_found"
48
+ expect(testcache["ISO(ISO 111111119115-1)"]["fetched"].to_s).to eq Date.today.to_s
49
+ expect(testcache["ISO(ISO 111111119115-1)"]["bib"]).to eq "not_found"
50
50
  end
51
51
  testcache = PStore.new "testcache2"
52
52
  testcache.transaction do
53
- expect(testcache["ISO 111111119115-1"]["fetched"].to_s).to eq Date.today.to_s
54
- expect(testcache["ISO 111111119115-1"]["bib"]).to eq "not_found"
53
+ expect(testcache["ISO(ISO 111111119115-1)"]["fetched"].to_s).to eq Date.today.to_s
54
+ expect(testcache["ISO(ISO 111111119115-1)"]["bib"]).to eq "not_found"
55
55
  end
56
56
  end
57
57
 
@@ -72,18 +72,18 @@ RSpec.describe Relaton::Db do
72
72
 
73
73
  it "get GB reference and cache it" do
74
74
  stub_bib Gbbib::GbBibliography
75
- bib = @db.fetch "GB Standard GB/T 20223", "2006", {}
75
+ bib = @db.fetch "CN(GB/T 20223)", "2006", {}
76
76
  expect(bib).to be_instance_of Gbbib::GbBibliographicItem
77
77
  expect(bib.to_xml).to include "<bibitem type=\"standard\" id=\"GB/T20223\">"
78
78
  expect(File.exist?("testcache")).to be true
79
79
  expect(File.exist?("testcache2")).to be true
80
80
  testcache = PStore.new "testcache"
81
81
  testcache.transaction true do
82
- expect(testcache["GB Standard GB/T 20223:2006"]["bib"].to_xml).to include "<bibitem type=\"standard\" id=\"GB/T20223\">"
82
+ expect(testcache["CN(GB/T 20223:2006)"]["bib"].to_xml).to include "<bibitem type=\"standard\" id=\"GB/T20223\">"
83
83
  end
84
84
  testcache = PStore.new "testcache2"
85
85
  testcache.transaction do
86
- expect(testcache["GB Standard GB/T 20223:2006"]["bib"].to_xml).to include "<bibitem type=\"standard\" id=\"GB/T20223\">"
86
+ expect(testcache["CN(GB/T 20223:2006)"]["bib"].to_xml).to include "<bibitem type=\"standard\" id=\"GB/T20223\">"
87
87
  end
88
88
  end
89
89
 
@@ -96,11 +96,11 @@ RSpec.describe Relaton::Db do
96
96
  expect(File.exist?("testcache2")).to be true
97
97
  testcache = PStore.new "testcache"
98
98
  testcache.transaction true do
99
- expect(testcache["RFC 8341"]["bib"].to_xml).to include "<bibitem id=\"RFC8341\">"
99
+ expect(testcache["IETF(RFC 8341)"]["bib"].to_xml).to include "<bibitem id=\"RFC8341\">"
100
100
  end
101
101
  testcache = PStore.new "testcache2"
102
102
  testcache.transaction do
103
- expect(testcache["RFC 8341"]["bib"].to_xml).to include "<bibitem id=\"RFC8341\">"
103
+ expect(testcache["IETF(RFC 8341)"]["bib"].to_xml).to include "<bibitem id=\"RFC8341\">"
104
104
  end
105
105
  end
106
106
 
Binary file
Binary file
Binary file
@@ -6,7 +6,7 @@
6
6
  <uri type="src">https://www.iso.org/standard/53798.html</uri>
7
7
  <uri type="obp">https://www.iso.org/obp/ui/#!iso:std:53798:en</uri>
8
8
  <uri type="rss">https://www.iso.org/contents/data/standard/05/37/53798.detail.rss</uri>
9
- <docidentifier>ISO 19115-1</docidentifier>
9
+ <docidentifier type="ISO">ISO 19115-1</docidentifier>
10
10
  <contributor>
11
11
  <role type="publisher"/>
12
12
  <organization>
@@ -53,7 +53,7 @@
53
53
  <uri type="src">https://www.iso.org/standard/53798.html</uri>
54
54
  <uri type="obp">https://www.iso.org/obp/ui/#!iso:std:53798:en</uri>
55
55
  <uri type="rss">https://www.iso.org/contents/data/standard/05/37/53798.detail.rss</uri>
56
- <docidentifier>ISO 19115-1</docidentifier>
56
+ <docidentifier type="ISO">ISO 19115-1:2014</docidentifier>
57
57
  <date type="published">
58
58
  <on>2014</on>
59
59
  </date>
@@ -121,7 +121,7 @@
121
121
  <uri type="src">https://www.iso.org/standard/39229.html</uri>
122
122
  <uri type="obp">https://www.iso.org/obp/ui/#!iso:std:39229:en</uri>
123
123
  <uri type="rss">https://www.iso.org/contents/data/standard/03/92/39229.detail.rss</uri>
124
- <docidentifier>ISO 19115-2</docidentifier>
124
+ <docidentifier type="ISO">ISO 19115-2</docidentifier>
125
125
  <contributor>
126
126
  <role type="publisher"/>
127
127
  <organization>
@@ -158,7 +158,7 @@
158
158
  <uri type="src">https://www.iso.org/standard/39229.html</uri>
159
159
  <uri type="obp">https://www.iso.org/obp/ui/#!iso:std:39229:en</uri>
160
160
  <uri type="rss">https://www.iso.org/contents/data/standard/03/92/39229.detail.rss</uri>
161
- <docidentifier>ISO 19115-2</docidentifier>
161
+ <docidentifier type="ISO">ISO 19115-2:2009</docidentifier>
162
162
  <date type="published">
163
163
  <on>2009</on>
164
164
  </date>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-25 00:00:00.000000000 Z
11
+ date: 2018-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: algoliasearch
@@ -30,56 +30,56 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.1
33
+ version: 0.3.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.2.1
40
+ version: 0.3.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: isobib
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.2.0
47
+ version: 0.3.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.2.0
54
+ version: 0.3.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rfcbib
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.2.2
61
+ version: 0.3.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.2.2
68
+ version: 0.3.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: iso-bib-item
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.2.3
75
+ version: 0.3.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.2.3
82
+ version: 0.3.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '9.1'
103
+ version: '10.0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '9.1'
110
+ version: '10.0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: equivalent-xml
113
113
  requirement: !ruby/object:Gem::Requirement