relaton-iec 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .vscode/
10
+ .rubocop-https---raw-githubusercontent-com-riboseinc-oss-guides-master-ci-rubocop-yml
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
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,16 @@
1
+ language: ruby
2
+ cache: bundler
3
+ os:
4
+ - linux
5
+ - osx
6
+ rvm:
7
+ - 2.5
8
+ - 2.4
9
+ - 2.3
10
+ - ruby-head
11
+ before_install:
12
+ - gem install bundler -v 2.0.1
13
+ - bundle update
14
+ matrix:
15
+ allow_failures:
16
+ - rvm: ruby-head
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in relaton_iec.gemspec
6
+ gemspec
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
@@ -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
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -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
@@ -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