relaton-iec 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 +16 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +92 -0
- data/LICENSE.txt +21 -0
- data/README.adoc +52 -0
- data/Rakefile +6 -0
- data/appveyor.yml +30 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/relaton/processor.rb +23 -0
- data/lib/relaton_iec.rb +10 -0
- data/lib/relaton_iec/hit.rb +51 -0
- data/lib/relaton_iec/hit_collection.rb +67 -0
- data/lib/relaton_iec/iec_bibliography.rb +156 -0
- data/lib/relaton_iec/scrapper.rb +413 -0
- data/lib/relaton_iec/statuses.yml +132 -0
- data/lib/relaton_iec/version.rb +3 -0
- data/relaton_iec.gemspec +38 -0
- metadata +235 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9e177f80a42aba2a914d20cf5ff1318bbb5799ef
|
4
|
+
data.tar.gz: 0421c70701e9b18c34efb723f1880841ffb8fa2b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 481e8b07607ad1846c7e935dd61274e60d16483b8d3113f0b474edad1fea26c2cfe25ff2dc8d63f07dd1a2ad43235cfd7bb89f5a5da4d1ee143a4d68124f112b
|
7
|
+
data.tar.gz: d34a555b072f86d185a2fee197e50e6286fae7083ca88da39c091508efca53ac2f9487473b41d469838d0906997f5b8fa2572e768da2551e0bf7deb20d98b10e
|
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
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
relaton-iec (0.1.0)
|
5
|
+
addressable
|
6
|
+
relaton-iso-bib (~> 0.1.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.6.0)
|
12
|
+
public_suffix (>= 2.0.2, < 4.0)
|
13
|
+
byebug (10.0.2)
|
14
|
+
coderay (1.1.2)
|
15
|
+
crack (0.4.3)
|
16
|
+
safe_yaml (~> 1.0.0)
|
17
|
+
debase (0.2.2)
|
18
|
+
debase-ruby_core_source (>= 0.10.2)
|
19
|
+
debase-ruby_core_source (0.10.4)
|
20
|
+
diff-lcs (1.3)
|
21
|
+
docile (1.3.1)
|
22
|
+
equivalent-xml (0.6.0)
|
23
|
+
nokogiri (>= 1.4.3)
|
24
|
+
hashdiff (0.3.8)
|
25
|
+
isoics (0.1.7)
|
26
|
+
json (2.1.0)
|
27
|
+
method_source (0.9.2)
|
28
|
+
mini_portile2 (2.3.0)
|
29
|
+
nokogiri (1.8.5)
|
30
|
+
mini_portile2 (~> 2.3.0)
|
31
|
+
pry (0.12.2)
|
32
|
+
coderay (~> 1.1.0)
|
33
|
+
method_source (~> 0.9.0)
|
34
|
+
pry-byebug (3.6.0)
|
35
|
+
byebug (~> 10.0)
|
36
|
+
pry (~> 0.10)
|
37
|
+
public_suffix (3.1.0)
|
38
|
+
rake (10.5.0)
|
39
|
+
relaton-bib (0.1.6)
|
40
|
+
addressable
|
41
|
+
nokogiri (~> 1.8.4)
|
42
|
+
relaton-iso-bib (0.1.0)
|
43
|
+
isoics (~> 0.1.6)
|
44
|
+
nokogiri (~> 1.8.4)
|
45
|
+
relaton-bib (~> 0.1.5)
|
46
|
+
ruby_deep_clone (~> 0.8.0)
|
47
|
+
rspec (3.8.0)
|
48
|
+
rspec-core (~> 3.8.0)
|
49
|
+
rspec-expectations (~> 3.8.0)
|
50
|
+
rspec-mocks (~> 3.8.0)
|
51
|
+
rspec-core (3.8.0)
|
52
|
+
rspec-support (~> 3.8.0)
|
53
|
+
rspec-expectations (3.8.2)
|
54
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
55
|
+
rspec-support (~> 3.8.0)
|
56
|
+
rspec-mocks (3.8.0)
|
57
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
58
|
+
rspec-support (~> 3.8.0)
|
59
|
+
rspec-support (3.8.0)
|
60
|
+
ruby-debug-ide (0.6.1)
|
61
|
+
rake (>= 0.8.1)
|
62
|
+
ruby_deep_clone (0.8.0)
|
63
|
+
safe_yaml (1.0.4)
|
64
|
+
simplecov (0.16.1)
|
65
|
+
docile (~> 1.1)
|
66
|
+
json (>= 1.8, < 3)
|
67
|
+
simplecov-html (~> 0.10.0)
|
68
|
+
simplecov-html (0.10.2)
|
69
|
+
vcr (4.0.0)
|
70
|
+
webmock (3.5.1)
|
71
|
+
addressable (>= 2.3.6)
|
72
|
+
crack (>= 0.3.2)
|
73
|
+
hashdiff
|
74
|
+
|
75
|
+
PLATFORMS
|
76
|
+
ruby
|
77
|
+
|
78
|
+
DEPENDENCIES
|
79
|
+
bundler (~> 2.0.1)
|
80
|
+
debase
|
81
|
+
equivalent-xml (~> 0.6)
|
82
|
+
pry-byebug
|
83
|
+
rake (~> 10.0)
|
84
|
+
relaton-iec!
|
85
|
+
rspec (~> 3.0)
|
86
|
+
ruby-debug-ide
|
87
|
+
simplecov
|
88
|
+
vcr
|
89
|
+
webmock
|
90
|
+
|
91
|
+
BUNDLED WITH
|
92
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 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,52 @@
|
|
1
|
+
= RelatonIec: retrieve IEC Standards for bibliographic use using the BibliographicItem model
|
2
|
+
|
3
|
+
image:https://img.shields.io/gem/v/relaton_iec.svg["Gem Version", link="https://rubygems.org/gems/relaton_iec"]
|
4
|
+
image:https://img.shields.io/travis/metanorma/relaton_iec/master.svg["Build Status", link="https://travis-ci.com/metanorma/relaton_iec"]
|
5
|
+
image:https://ci.appveyor.com/api/projects/status/ewepoefhla5h76p7?svg=true["Appveyor Build Status", link="https://ci.appveyor.com/project/ribose/relaton_iec"]
|
6
|
+
image:https://codeclimate.com/github/metanorma/relaton_iec/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/relaton_iec"]
|
7
|
+
|
8
|
+
RelatonIec is a Ruby gem that implements the https://github.com/metanorma/metanorma-model-iso#iso-bibliographic-item[IsoBibliographicItem model].
|
9
|
+
|
10
|
+
You can use it to retrieve metadata of IEC Standards from https://www.iec.ch, and access such metadata through the `IsoBibliographicItem` object.
|
11
|
+
|
12
|
+
== Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
[source,ruby]
|
17
|
+
----
|
18
|
+
gem 'relaton_iec'
|
19
|
+
----
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install relaton_iec
|
28
|
+
|
29
|
+
== Usage
|
30
|
+
|
31
|
+
Refer to https://github.com/metanorma/relaton-iso/blob/master/README.adoc: the usage interface is identical.
|
32
|
+
|
33
|
+
== Development
|
34
|
+
|
35
|
+
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.
|
36
|
+
|
37
|
+
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).
|
38
|
+
|
39
|
+
|
40
|
+
== Exceptional Citations
|
41
|
+
|
42
|
+
This gem retrieves bibliographic descriptions of ISO documents by doing searches on the ISO website, http://www.iso.org, and screenscraping the document that matches the queried document identifier. The following documents are not returned as search results from the ISO website, and the gem returns manually generated references to them.
|
43
|
+
|
44
|
+
* `IEV`: used in the metanorma-iso gem to reference Electropedia entries generically. Is resolved to an "all parts" reference to IEC 60050, which in turn is resolved into the specific documents cited by their top-level clause.
|
45
|
+
|
46
|
+
== Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/metanorma/relaton-iec.
|
49
|
+
|
50
|
+
== License
|
51
|
+
|
52
|
+
The gem is available as open source under the terms of the https://opensource.org/licenses/MIT[MIT License].
|
data/Rakefile
ADDED
data/appveyor.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
version: '{build}'
|
2
|
+
|
3
|
+
environment:
|
4
|
+
matrix:
|
5
|
+
- RUBY_VERSION: 25
|
6
|
+
- RUBY_VERSION: 24
|
7
|
+
- RUBY_VERSION: 23
|
8
|
+
- RUBY_VERSION: _trunk
|
9
|
+
|
10
|
+
matrix:
|
11
|
+
allow_failures:
|
12
|
+
- RUBY_VERSION: _trunk
|
13
|
+
|
14
|
+
install:
|
15
|
+
- ps: . { iwr -useb https://raw.githubusercontent.com/metanorma/metanorma-build-scripts/master/appveyor.ps1 } | iex
|
16
|
+
- refreshenv
|
17
|
+
|
18
|
+
build_script:
|
19
|
+
- set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
|
20
|
+
- bundle update
|
21
|
+
- bundle install
|
22
|
+
|
23
|
+
before_test:
|
24
|
+
- ruby -v
|
25
|
+
- gem -v
|
26
|
+
- bundle -v
|
27
|
+
|
28
|
+
test_script:
|
29
|
+
- bundle exec rake
|
30
|
+
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "relaton_iec"
|
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/setup
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "relaton/processor"
|
2
|
+
|
3
|
+
module Relaton
|
4
|
+
module RelatonIec
|
5
|
+
class Processor < Relaton::Processor
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@short = :relaton_iec
|
9
|
+
@prefix = "IEC"
|
10
|
+
@defaultprefix = %r{^(IEC)[ /]|^IEV($| )}
|
11
|
+
@idtype = "IEC"
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(code, date, opts)
|
15
|
+
::RelatonIec::IecBibliography.get(code, date, opts)
|
16
|
+
end
|
17
|
+
|
18
|
+
def from_xml(xml)
|
19
|
+
RelatonIsoBib::XMLParser.from_xml xml
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/relaton_iec.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "relaton_iec/version"
|
2
|
+
require "relaton_iec/iec_bibliography"
|
3
|
+
if defined? Relaton
|
4
|
+
require_relative "relaton/processor"
|
5
|
+
Relaton::Registry.instance.register(Relaton::RelatonIec::Processor)
|
6
|
+
end
|
7
|
+
|
8
|
+
module RelatonIec
|
9
|
+
# Your code goes here...
|
10
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RelatonIec
|
4
|
+
# Hit.
|
5
|
+
class Hit
|
6
|
+
# @return [Isobib::HitCollection]
|
7
|
+
attr_reader :hit_collection
|
8
|
+
|
9
|
+
# @return [Array<Hash>]
|
10
|
+
attr_reader :hit
|
11
|
+
|
12
|
+
# @param hit [Hash]
|
13
|
+
# @param hit_collection [Isobib:HitCollection]
|
14
|
+
def initialize(hit, hit_collection = nil)
|
15
|
+
@hit = hit
|
16
|
+
@hit_collection = hit_collection
|
17
|
+
end
|
18
|
+
|
19
|
+
# Parse page.
|
20
|
+
# @return [Isobib::IsoBibliographicItem]
|
21
|
+
def fetch
|
22
|
+
@fetch ||= Scrapper.parse_page @hit
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [String]
|
26
|
+
def to_s
|
27
|
+
inspect
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [String]
|
31
|
+
def inspect
|
32
|
+
"<#{self.class}:#{format('%#.14x', object_id << 1)} "\
|
33
|
+
"@text=\"#{@hit_collection&.text}\" "\
|
34
|
+
"@fetched=\"#{!@fetch.nil?}\" "\
|
35
|
+
"@fullIdentifier=\"#{@fetch&.shortref(nil)}\" "\
|
36
|
+
"@title=\"#{@hit[:code]}\">"
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [String]
|
40
|
+
def to_xml(opts = {})
|
41
|
+
#if builder
|
42
|
+
#fetch.to_xml builder, opts
|
43
|
+
#else
|
44
|
+
builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
|
45
|
+
fetch.to_xml xml, opts
|
46
|
+
end
|
47
|
+
builder.doc.root.to_xml
|
48
|
+
#end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "relaton_iec/hit"
|
4
|
+
require "addressable/uri"
|
5
|
+
|
6
|
+
module RelatonIec
|
7
|
+
# Page of hit collection.
|
8
|
+
class HitCollection < Array
|
9
|
+
|
10
|
+
DOMAIN = "https://webstore.iec.ch"
|
11
|
+
|
12
|
+
# @return [TrueClass, FalseClass]
|
13
|
+
attr_reader :fetched
|
14
|
+
|
15
|
+
# @return [String]
|
16
|
+
attr_reader :text
|
17
|
+
|
18
|
+
# @return [String]
|
19
|
+
attr_reader :year
|
20
|
+
|
21
|
+
# @param ref_nbr [String]
|
22
|
+
# @param year [String]
|
23
|
+
def initialize(ref_nbr, year = nil) #(text, hit_pages = nil)
|
24
|
+
@text = ref_nbr
|
25
|
+
@year = year
|
26
|
+
from, to = nil
|
27
|
+
if year
|
28
|
+
from = Date.strptime year, "%Y"
|
29
|
+
to = from.next_year.prev_day
|
30
|
+
end
|
31
|
+
url = "#{DOMAIN}/searchkey&RefNbr=#{ref_nbr}&From=#{from}&To=#{to}&start=1"
|
32
|
+
doc = Nokogiri::HTML OpenURI.open_uri(::Addressable::URI.parse(url).normalize)
|
33
|
+
hits = doc.css("ul.search-results > li").map do |h|
|
34
|
+
link = h.at('a[@href!="#"]')
|
35
|
+
code = link.text.tr [194, 160].pack("c*").force_encoding("UTF-8"), ""
|
36
|
+
title = h.xpath("text()").text.gsub(/[\r\n]/, "")
|
37
|
+
url = DOMAIN + link[:href]
|
38
|
+
Hit.new({ code: code, title: title, url: url }, self)
|
39
|
+
end
|
40
|
+
concat hits
|
41
|
+
# concat(hits.map { |h| Hit.new(h, self) })
|
42
|
+
@fetched = false
|
43
|
+
# @hit_pages = hit_pages
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [RelatonIec::HitCollection]
|
47
|
+
def fetch
|
48
|
+
workers = RelatonBib::WorkersPool.new 4
|
49
|
+
workers.worker(&:fetch)
|
50
|
+
each do |hit|
|
51
|
+
workers << hit
|
52
|
+
end
|
53
|
+
workers.end
|
54
|
+
workers.result
|
55
|
+
@fetched = true
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_s
|
60
|
+
inspect
|
61
|
+
end
|
62
|
+
|
63
|
+
def inspect
|
64
|
+
"<#{self.class}:#{format('%#.14x', object_id << 1)} @fetched=#{@fetched}>"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|