relaton-calconnect 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +10 -0
- data/.travis.yml +18 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +84 -0
- data/LICENSE.txt +21 -0
- data/README.adoc +123 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/rspec +29 -0
- data/bin/setup +8 -0
- data/lib/relaton_calconnect.rb +14 -0
- data/lib/relaton_calconnect/cc_bibliographic_item.rb +8 -0
- data/lib/relaton_calconnect/cc_bibliography.rb +85 -0
- data/lib/relaton_calconnect/hash_converter.rb +5 -0
- data/lib/relaton_calconnect/hit.rb +12 -0
- data/lib/relaton_calconnect/hit_collection.rb +80 -0
- data/lib/relaton_calconnect/processor.rb +35 -0
- data/lib/relaton_calconnect/scrapper.rb +41 -0
- data/lib/relaton_calconnect/version.rb +3 -0
- data/lib/relaton_calconnect/xml_parser.rb +12 -0
- data/relaton_calconnect.gemspec +41 -0
- metadata +222 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9f236a8d9cdbe6bc2e8f496ec0de9859587dc78bb66965f85de32a2cdea85425
|
4
|
+
data.tar.gz: e65812c95d64bd1396fabe17de060bf0b3c53bad0112434076577c944e5383e5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 81d25d7fe6209cb16d5a77e318ba859886f568f7b0bc5fa5ea8c362d31ad4a3251fa257a8b6ba3e1bb976d0cb846cc2a61e60ebc8e3ab53e951ca5add375778c
|
7
|
+
data.tar.gz: 0caecfd261ae5315cb5e4fb1ffbcd5ad35c1cd823531dfcfd32ba72c77bffe17a9a849f857b70bac43ef4058dd348cdcd371634dad7a47ead5cb6ffce313e8d5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# This project follows the Ribose OSS style guide.
|
2
|
+
# https://github.com/riboseinc/oss-guides
|
3
|
+
# All project-specific additions and overrides should be specified in this file.
|
4
|
+
|
5
|
+
inherit_from:
|
6
|
+
- https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
|
7
|
+
AllCops:
|
8
|
+
TargetRubyVersion: 2.3
|
9
|
+
Rails:
|
10
|
+
Enabled: true
|
data/.travis.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Auto-generated !!! Do not edit it manually
|
2
|
+
# use ci-master https://github.com/metanorma/metanorma-build-scripts
|
3
|
+
language: ruby
|
4
|
+
cache: bundler
|
5
|
+
os:
|
6
|
+
- linux
|
7
|
+
- osx
|
8
|
+
rvm:
|
9
|
+
- 2.6
|
10
|
+
- 2.5
|
11
|
+
- 2.4
|
12
|
+
- ruby-head
|
13
|
+
before_install:
|
14
|
+
- gem install bundler -v "~> 2"
|
15
|
+
- bundle update
|
16
|
+
matrix:
|
17
|
+
allow_failures:
|
18
|
+
- rvm: ruby-head
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
relaton-calconnect (0.1.0)
|
5
|
+
faraday
|
6
|
+
relaton-iso-bib (~> 0.3.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.7.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
13
|
+
crack (0.4.3)
|
14
|
+
safe_yaml (~> 1.0.0)
|
15
|
+
debase (0.2.4.1)
|
16
|
+
debase-ruby_core_source (>= 0.10.2)
|
17
|
+
debase-ruby_core_source (0.10.5)
|
18
|
+
diff-lcs (1.3)
|
19
|
+
docile (1.3.2)
|
20
|
+
equivalent-xml (0.6.0)
|
21
|
+
nokogiri (>= 1.4.3)
|
22
|
+
faraday (0.15.4)
|
23
|
+
multipart-post (>= 1.2, < 3)
|
24
|
+
hashdiff (1.0.0)
|
25
|
+
isoics (0.1.8)
|
26
|
+
json (2.2.0)
|
27
|
+
mini_portile2 (2.4.0)
|
28
|
+
multipart-post (2.1.1)
|
29
|
+
nokogiri (1.10.4)
|
30
|
+
mini_portile2 (~> 2.4.0)
|
31
|
+
public_suffix (4.0.1)
|
32
|
+
rake (10.5.0)
|
33
|
+
relaton-bib (0.3.12)
|
34
|
+
addressable
|
35
|
+
nokogiri
|
36
|
+
relaton-iso-bib (0.3.12)
|
37
|
+
isoics (~> 0.1.6)
|
38
|
+
relaton-bib (~> 0.3.0)
|
39
|
+
ruby_deep_clone (~> 0.8.0)
|
40
|
+
rspec (3.8.0)
|
41
|
+
rspec-core (~> 3.8.0)
|
42
|
+
rspec-expectations (~> 3.8.0)
|
43
|
+
rspec-mocks (~> 3.8.0)
|
44
|
+
rspec-core (3.8.2)
|
45
|
+
rspec-support (~> 3.8.0)
|
46
|
+
rspec-expectations (3.8.4)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.8.0)
|
49
|
+
rspec-mocks (3.8.1)
|
50
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
+
rspec-support (~> 3.8.0)
|
52
|
+
rspec-support (3.8.2)
|
53
|
+
ruby-debug-ide (0.7.0)
|
54
|
+
rake (>= 0.8.1)
|
55
|
+
ruby_deep_clone (0.8.0)
|
56
|
+
safe_yaml (1.0.5)
|
57
|
+
simplecov (0.17.1)
|
58
|
+
docile (~> 1.1)
|
59
|
+
json (>= 1.8, < 3)
|
60
|
+
simplecov-html (~> 0.10.0)
|
61
|
+
simplecov-html (0.10.2)
|
62
|
+
vcr (5.0.0)
|
63
|
+
webmock (3.7.1)
|
64
|
+
addressable (>= 2.3.6)
|
65
|
+
crack (>= 0.3.2)
|
66
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
67
|
+
|
68
|
+
PLATFORMS
|
69
|
+
ruby
|
70
|
+
|
71
|
+
DEPENDENCIES
|
72
|
+
bundler (~> 2.0)
|
73
|
+
debase
|
74
|
+
equivalent-xml (~> 0.6)
|
75
|
+
rake (~> 10.0)
|
76
|
+
relaton-calconnect!
|
77
|
+
rspec (~> 3.0)
|
78
|
+
ruby-debug-ide
|
79
|
+
simplecov
|
80
|
+
vcr
|
81
|
+
webmock
|
82
|
+
|
83
|
+
BUNDLED WITH
|
84
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Andrei Kislichenko
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.adoc
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
= RelatonCalconnect
|
2
|
+
|
3
|
+
RelatonCalconnect is a Ruby gem that implements the https://github.com/metanorma/metanorma-model-iso#iso-bibliographic-item[IsoBibliographicItem model].
|
4
|
+
|
5
|
+
You can use it to retrieve metadata of Calconnect Standards from https://standards.calconnect.org, and access such metadata through the `CcBibliographicItem` object.
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
[source,ruby]
|
12
|
+
----
|
13
|
+
gem 'relaton-calconnect'
|
14
|
+
----
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install relaton-calconnect
|
23
|
+
|
24
|
+
== Usage
|
25
|
+
|
26
|
+
=== Search for a standard using keywords
|
27
|
+
|
28
|
+
[source,ruby]
|
29
|
+
----
|
30
|
+
require 'relaton_calconnect'
|
31
|
+
|
32
|
+
hits = RelatonCalconnect::CcBibliography.search("CC/DIR 10005:2019")
|
33
|
+
=> [<RelatonCalconnect::Hit:0x007f9a765185c0 @text="CC/DIR 10005:2019" @fetched="false" @fullIdentifier="" @title="">]
|
34
|
+
|
35
|
+
item = hits[0].fetch
|
36
|
+
=> #<RelatonCalconnect::CcBibliographicItem:0x007f9a766b15d0
|
37
|
+
...
|
38
|
+
----
|
39
|
+
|
40
|
+
=== XML serialization
|
41
|
+
|
42
|
+
[source,ruby]
|
43
|
+
----
|
44
|
+
item.to_xml
|
45
|
+
=> "<bibitem id=CC/DIR10005-2019 type=directive>
|
46
|
+
<title format=text/plain language=en>Guidelines for the implementation of the CalConnect patent policy</title>
|
47
|
+
<uri type=xml>csd/cc-10005.xml</uri>
|
48
|
+
<uri type=pdf>csd/cc-10005.pdf</uri>
|
49
|
+
<uri type=doc>csd/cc-10005.doc</uri>
|
50
|
+
<uri type=html>csd/cc-10005.html</uri>
|
51
|
+
<uri type=rxl>csd/cc-10005.rxl</uri>
|
52
|
+
<docidentifier type=CC>CC/DIR 10005:2019</docidentifier>
|
53
|
+
...
|
54
|
+
</bibitem>
|
55
|
+
----
|
56
|
+
With argument `bibdata: true` it ouputs XML wrapped by `bibdata` element and adds flavour `ext` element.
|
57
|
+
[source,ruby]
|
58
|
+
----
|
59
|
+
item.to_xml bibdata: true
|
60
|
+
=> "<bibdata type=directive>
|
61
|
+
<title format=text/plain language=en>Guidelines for the implementation of the CalConnect patent policy</title>
|
62
|
+
<uri type=xml>csd/cc-10005.xml</uri>
|
63
|
+
<uri type=pdf>csd/cc-10005.pdf</uri>
|
64
|
+
<uri type=doc>csd/cc-10005.doc</uri>
|
65
|
+
<uri type=html>csd/cc-10005.html</uri>
|
66
|
+
<uri type=rxl>csd/cc-10005.rxl</uri>
|
67
|
+
<docidentifier type=CC>CC/DIR 10005:2019</docidentifier>
|
68
|
+
...
|
69
|
+
<ext>
|
70
|
+
<doctype>directive</doctype>
|
71
|
+
<editorialgroup>
|
72
|
+
<technical-committee>PUBLISH</technical-committee>
|
73
|
+
</editorialgroup>
|
74
|
+
</ext>
|
75
|
+
</bibdata>"
|
76
|
+
----
|
77
|
+
|
78
|
+
=== Get code, and year
|
79
|
+
[source,ruby]
|
80
|
+
----
|
81
|
+
RelatonCalconnect::CcBibliography.get "CC/DIR 10005", "2019", {}
|
82
|
+
fetching CC/DIR 10005...
|
83
|
+
=> #<RelatonCalconnect::CcBibliographicItem:0x007f9a73dfa290
|
84
|
+
...
|
85
|
+
----
|
86
|
+
|
87
|
+
=== Create bibliographic item from XML
|
88
|
+
[source,ruby]
|
89
|
+
----
|
90
|
+
RelatonCalconnect::XMLParser.from_xml File.read('spec/fixtures/cc_dir_10005_2019.xml')
|
91
|
+
=> #<RelatonCalconnect::CcBibliographicItem:0x007f9a7423dde8
|
92
|
+
...
|
93
|
+
----
|
94
|
+
|
95
|
+
=== Create bibliographic item from YAML
|
96
|
+
[source,ruby]
|
97
|
+
----
|
98
|
+
hash = YAML.load_file 'spec/fixtures/cc_dir_10005_2019.yml'
|
99
|
+
=> {"id"=>"CC/DIR10005-2019",
|
100
|
+
...
|
101
|
+
|
102
|
+
bib_hash = RelatonCalconnect::HashConverter.hash_to_bib hash
|
103
|
+
=> {:id=>"CC/DIR10005-2019",
|
104
|
+
...
|
105
|
+
|
106
|
+
RelatonCalconnect::CcBibliographicItem.new bib_hash
|
107
|
+
=> #<RelatonCalconnect::CcBibliographicItem:0x007fc5a0109f88
|
108
|
+
...
|
109
|
+
----
|
110
|
+
|
111
|
+
== Development
|
112
|
+
|
113
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
114
|
+
|
115
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
116
|
+
|
117
|
+
== Contributing
|
118
|
+
|
119
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/calconnect/relaton_calconnect.
|
120
|
+
|
121
|
+
== License
|
122
|
+
|
123
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "relaton_calconnect"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/rspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rspec' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/setup
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "relaton_iso_bib"
|
2
|
+
require "relaton_calconnect/version"
|
3
|
+
require "relaton_calconnect/cc_bibliography"
|
4
|
+
require "relaton_calconnect/hit_collection"
|
5
|
+
require "relaton_calconnect/hit"
|
6
|
+
require "relaton_calconnect/scrapper"
|
7
|
+
require "relaton_calconnect/cc_bibliographic_item"
|
8
|
+
require "relaton_calconnect/xml_parser"
|
9
|
+
require "relaton_calconnect/hash_converter"
|
10
|
+
|
11
|
+
module RelatonCalconnect
|
12
|
+
class Error < StandardError; end
|
13
|
+
# Your code goes here...
|
14
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module RelatonCalconnect
|
2
|
+
class CcBibliography
|
3
|
+
class << self
|
4
|
+
# @param text [String]
|
5
|
+
# @return [RelatonCalconnect::HitCollection]
|
6
|
+
def search(text, year = nil, opts = {})
|
7
|
+
HitCollection.new text, year, opts
|
8
|
+
rescue Faraday::Error::ConnectionFailed
|
9
|
+
raise RelatonBib::RequestError, "Could not access https://standards.calconnect.org"
|
10
|
+
end
|
11
|
+
|
12
|
+
# @param code [String] the OGC standard Code to look up (e..g "8200")
|
13
|
+
# @param year [String] the year the standard was published (optional)
|
14
|
+
#
|
15
|
+
# @param opts [Hash] options
|
16
|
+
# @option opts [TrueClass, FalseClass] :all_parts restricted to all parts
|
17
|
+
# if all-parts reference is required
|
18
|
+
# @option opts [TrueClass, FalseClass] :bibdata
|
19
|
+
#
|
20
|
+
# @return [RelatonCalconnect::CcBibliographicItem]
|
21
|
+
def get(code, year = nil, opts = {})
|
22
|
+
if year.nil?
|
23
|
+
/^(?<code1>[^\s]+(\s\w+)?\s[\d-]+):?(?<year1>\d{4})?/ =~ code
|
24
|
+
unless code1.nil?
|
25
|
+
code = code1
|
26
|
+
year = year1
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
result = bib_search_filter(code, year, opts) || (return nil)
|
31
|
+
ret = bib_results_filter(result, year)
|
32
|
+
return ret[:ret] if ret[:ret]
|
33
|
+
|
34
|
+
fetch_ref_err(code, year, ret[:years])
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def bib_search_filter(code, year, opts)
|
40
|
+
warn "fetching #{code}..."
|
41
|
+
search(code, year, opts)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Sort through the results from RelatonNist, fetching them three at a time,
|
45
|
+
# and return the first result that matches the code,
|
46
|
+
# matches the year (if provided), and which # has a title (amendments do not).
|
47
|
+
# Only expects the first page of results to be populated.
|
48
|
+
# Does not match corrigenda etc (e.g. ISO 3166-1:2006/Cor 1:2007)
|
49
|
+
# If no match, returns any years which caused mismatch, for error reporting
|
50
|
+
#
|
51
|
+
# @param result
|
52
|
+
# @param opts [Hash] options
|
53
|
+
#
|
54
|
+
# @return [Hash]
|
55
|
+
def bib_results_filter(result, year)
|
56
|
+
missed_years = []
|
57
|
+
result.each do |r|
|
58
|
+
item = r.fetch
|
59
|
+
return { ret: item } if !year
|
60
|
+
|
61
|
+
item.date.select { |d| d.type == "published" }.each do |d|
|
62
|
+
return { ret: item } if year.to_i == d.on.year
|
63
|
+
|
64
|
+
missed_years << d.on.year
|
65
|
+
end
|
66
|
+
end
|
67
|
+
{ years: missed_years }
|
68
|
+
end
|
69
|
+
|
70
|
+
# @param code [Strig]
|
71
|
+
# @param year [String]
|
72
|
+
# @param missed_years [Array<Strig>]
|
73
|
+
def fetch_ref_err(code, year, missed_years)
|
74
|
+
id = year ? "#{code} year #{year}" : code
|
75
|
+
warn "WARNING: no match found online for #{id}. "\
|
76
|
+
"The code must be exactly like it is on the standards website."
|
77
|
+
unless missed_years.empty?
|
78
|
+
warn "(There was no match for #{year}, though there were matches "\
|
79
|
+
"found for #{missed_years.join(', ')}.)"
|
80
|
+
end
|
81
|
+
nil
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module RelatonCalconnect
|
2
|
+
class Hit < RelatonBib::Hit
|
3
|
+
# @return [RelatonCalconnect::HitCollection]
|
4
|
+
attr_reader :hit_collection
|
5
|
+
|
6
|
+
# Parse page.
|
7
|
+
# @return [RelatonCalconnect::CcBliographicItem]
|
8
|
+
def fetch
|
9
|
+
@fetch ||= Scrapper.parse_page @hit
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "yaml"
|
3
|
+
require "fileutils"
|
4
|
+
|
5
|
+
module RelatonCalconnect
|
6
|
+
class HitCollection < RelatonBib::HitCollection
|
7
|
+
ENDPOINT = "https://standards.calconnect.org/relaton/index.yaml".freeze
|
8
|
+
# ENDPOINT = "http://127.0.0.1:4000/relaton/index.yaml".freeze
|
9
|
+
DATADIR = File.expand_path ".relaton/calconnect", Dir.home
|
10
|
+
DATAFILE = File.expand_path "bibliography.yml", DATADIR
|
11
|
+
ETAGFILE = File.expand_path "etag.txt", DATADIR
|
12
|
+
|
13
|
+
# @param ref [Strig]
|
14
|
+
# @param year [String]
|
15
|
+
# @param opts [Hash]
|
16
|
+
def initialize(ref, year = nil, _opts = {})
|
17
|
+
@text = ref
|
18
|
+
@year = year
|
19
|
+
@fetched = false
|
20
|
+
hits = from_yaml(ref).sort_by do |hit|
|
21
|
+
hit.hit["revdate"] ? Date.parse(hit.hit["revdate"]) : Date.new
|
22
|
+
end
|
23
|
+
concat hits.reverse
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
#
|
29
|
+
# Fetch data form yaml
|
30
|
+
#
|
31
|
+
# @param docid [String]
|
32
|
+
def from_yaml(docid, **_opts)
|
33
|
+
data["root"]["items"].select do |doc|
|
34
|
+
doc["docid"]["id"].include?(docid)
|
35
|
+
end.map { |h| Hit.new(h, self) }
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Fetches YAML data
|
40
|
+
#
|
41
|
+
# @return [Hash]
|
42
|
+
def data
|
43
|
+
FileUtils.mkdir_p DATADIR
|
44
|
+
ctime = File.ctime DATAFILE if File.exist? DATAFILE
|
45
|
+
fetch_data if !ctime || ctime.to_date < Date.today
|
46
|
+
@data ||= YAML.safe_load File.read(DATAFILE, encoding: "UTF-8")
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# fetch data form server and save it to file.
|
51
|
+
#
|
52
|
+
def fetch_data
|
53
|
+
resp = Faraday.new(ENDPOINT, headers: { "If-None-Match" => etag }).get
|
54
|
+
# return if there aren't any changes since last fetching
|
55
|
+
return unless resp.status == 200
|
56
|
+
|
57
|
+
self.etag = resp[:etag]
|
58
|
+
@data = YAML.safe_load resp.body
|
59
|
+
File.write DATAFILE, @data.to_yaml, encoding: "UTF-8"
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# Read ETag form file
|
64
|
+
#
|
65
|
+
# @return [String, NilClass]
|
66
|
+
def etag
|
67
|
+
@etag ||= if File.exist? ETAGFILE
|
68
|
+
File.read ETAGFILE, encoding: "UTF-8"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
#
|
73
|
+
# Save ETag to file
|
74
|
+
#
|
75
|
+
# @param tag [String]
|
76
|
+
def etag=(e_tag)
|
77
|
+
File.write ETAGFILE, e_tag, encoding: "UTF-8"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "relaton/processor"
|
2
|
+
|
3
|
+
module RelatonCalconnect
|
4
|
+
class Processor < Relaton::Processor
|
5
|
+
attr_reader :idtype
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@short = :relaton_calconnect
|
9
|
+
@prefix = "CC"
|
10
|
+
@defaultprefix = %r{^(CC)[ /]}
|
11
|
+
@idtype = "CC"
|
12
|
+
end
|
13
|
+
|
14
|
+
# @param code [String]
|
15
|
+
# @param date [String, NilClass] year
|
16
|
+
# @param opts [Hash]
|
17
|
+
# @return [RelatonCalconnect::CcBibliographicItem]
|
18
|
+
def get(code, date, opts)
|
19
|
+
::RelatonCalconnect::CcBibliography.get(code, date, opts)
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param xml [String]
|
23
|
+
# @return [RelatonCalconnect::CcBibliographicItem]
|
24
|
+
def from_xml(xml)
|
25
|
+
::RelatonCalconnect::XMLParser.from_xml xml
|
26
|
+
end
|
27
|
+
|
28
|
+
# @param hash [Hash]
|
29
|
+
# @return [RelatonIsoBib::CcBibliographicItem]
|
30
|
+
def hash_to_bib(hash)
|
31
|
+
item_hash = ::RelatonCalconnect::HashConverter.hash_to_bib(hash)
|
32
|
+
::RelatonCalconnect::CcBibliographicItem.new item_hash
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module RelatonCalconnect
|
2
|
+
module Scrapper
|
3
|
+
# DOMAIN = "https://standards.calconnect.org/".freeze
|
4
|
+
DOMAIN = "http://127.0.0.1:4000/".freeze
|
5
|
+
|
6
|
+
class << self
|
7
|
+
# papam hit [Hash]
|
8
|
+
# @return [RelatonOgc::OrcBibliographicItem]
|
9
|
+
def parse_page(hit)
|
10
|
+
link = hit["link"].detect { |l| l["type"] == "rxl" }
|
11
|
+
if link
|
12
|
+
bib_xml = fetch_bib_xml link["content"]
|
13
|
+
XMLParser.from_xml bib_xml
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# @param url [String]
|
20
|
+
# @return [String] XML
|
21
|
+
def fetch_bib_xml(url)
|
22
|
+
rxl = get_rxl url
|
23
|
+
uri_rxl = rxl.at("uri[@type='rxl']")
|
24
|
+
return rxl.to_xml unless uri_rxl
|
25
|
+
|
26
|
+
uri_xml = rxl.xpath("//uri").to_xml
|
27
|
+
rxl = get_rxl uri_rxl.text
|
28
|
+
docid = rxl.at "//docidentifier"
|
29
|
+
docid.add_previous_sibling uri_xml
|
30
|
+
rxl.to_xml
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param path [String]
|
34
|
+
# @return [Nokogiri::XML::Document]
|
35
|
+
def get_rxl(path)
|
36
|
+
resp = Faraday.get DOMAIN + path
|
37
|
+
Nokogiri::XML resp.body
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module RelatonCalconnect
|
2
|
+
class XMLParser < RelatonIsoBib::XMLParser
|
3
|
+
class << self
|
4
|
+
def from_xml(xml)
|
5
|
+
doc = Nokogiri::XML xml
|
6
|
+
doc.remove_namespaces!
|
7
|
+
cctitem = doc.at("/bibitem|/bibdata")
|
8
|
+
CcBibliographicItem.new(item_data(cctitem))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "relaton_calconnect/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "relaton-calconnect"
|
7
|
+
spec.version = RelatonCalconnect::VERSION
|
8
|
+
spec.authors = ["Ribose Inc."]
|
9
|
+
spec.email = ["open.source@ribose.com"]
|
10
|
+
|
11
|
+
spec.summary = "RelatonIso: retrieve CC Standards for bibliographic use "\
|
12
|
+
"using the IsoBibliographicItem model"
|
13
|
+
spec.description = "RelatonIso: retrieve CC Standards for bibliographic use "\
|
14
|
+
"using the IsoBibliographicItem model"
|
15
|
+
|
16
|
+
spec.homepage = "https://github.com/relaton/relaton-calconnect"
|
17
|
+
spec.license = "BSD-2-Clause"
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
30
|
+
spec.add_development_dependency "debase"
|
31
|
+
spec.add_development_dependency "equivalent-xml", "~> 0.6"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
+
spec.add_development_dependency "ruby-debug-ide"
|
35
|
+
spec.add_development_dependency "simplecov"
|
36
|
+
spec.add_development_dependency "vcr"
|
37
|
+
spec.add_development_dependency "webmock"
|
38
|
+
|
39
|
+
spec.add_dependency "faraday"
|
40
|
+
spec.add_dependency "relaton-iso-bib", "~> 0.3.0"
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,222 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: relaton-calconnect
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ribose Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: debase
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: equivalent-xml
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: ruby-debug-ide
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: vcr
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: faraday
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: relaton-iso-bib
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 0.3.0
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 0.3.0
|
167
|
+
description: 'RelatonIso: retrieve CC Standards for bibliographic use using the IsoBibliographicItem
|
168
|
+
model'
|
169
|
+
email:
|
170
|
+
- open.source@ribose.com
|
171
|
+
executables: []
|
172
|
+
extensions: []
|
173
|
+
extra_rdoc_files: []
|
174
|
+
files:
|
175
|
+
- ".gitignore"
|
176
|
+
- ".rspec"
|
177
|
+
- ".rubocop.yml"
|
178
|
+
- ".travis.yml"
|
179
|
+
- Gemfile
|
180
|
+
- Gemfile.lock
|
181
|
+
- LICENSE.txt
|
182
|
+
- README.adoc
|
183
|
+
- Rakefile
|
184
|
+
- bin/console
|
185
|
+
- bin/rspec
|
186
|
+
- bin/setup
|
187
|
+
- lib/relaton_calconnect.rb
|
188
|
+
- lib/relaton_calconnect/cc_bibliographic_item.rb
|
189
|
+
- lib/relaton_calconnect/cc_bibliography.rb
|
190
|
+
- lib/relaton_calconnect/hash_converter.rb
|
191
|
+
- lib/relaton_calconnect/hit.rb
|
192
|
+
- lib/relaton_calconnect/hit_collection.rb
|
193
|
+
- lib/relaton_calconnect/processor.rb
|
194
|
+
- lib/relaton_calconnect/scrapper.rb
|
195
|
+
- lib/relaton_calconnect/version.rb
|
196
|
+
- lib/relaton_calconnect/xml_parser.rb
|
197
|
+
- relaton_calconnect.gemspec
|
198
|
+
homepage: https://github.com/relaton/relaton-calconnect
|
199
|
+
licenses:
|
200
|
+
- BSD-2-Clause
|
201
|
+
metadata: {}
|
202
|
+
post_install_message:
|
203
|
+
rdoc_options: []
|
204
|
+
require_paths:
|
205
|
+
- lib
|
206
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
207
|
+
requirements:
|
208
|
+
- - ">="
|
209
|
+
- !ruby/object:Gem::Version
|
210
|
+
version: 2.4.0
|
211
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ">="
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
requirements: []
|
217
|
+
rubygems_version: 3.0.6
|
218
|
+
signing_key:
|
219
|
+
specification_version: 4
|
220
|
+
summary: 'RelatonIso: retrieve CC Standards for bibliographic use using the IsoBibliographicItem
|
221
|
+
model'
|
222
|
+
test_files: []
|