ietfbib 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +4 -0
- data/.travis.yml +14 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +66 -0
- data/LICENSE.txt +25 -0
- data/README.adoc +93 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ietfbib.gemspec +39 -0
- data/lib/ietfbib/rfc_bibliography.rb +24 -0
- data/lib/ietfbib/scrapper.rb +234 -0
- data/lib/ietfbib/version.rb +3 -0
- data/lib/ietfbib.rb +9 -0
- data/lib/relaton/processor.rb +17 -0
- metadata +161 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 8cb96d28c6f96907d215188af250f20b02557b7502cae3d32aff7b257676e2fc
|
|
4
|
+
data.tar.gz: e9813dfb0ffc2b9f107a0ecc3c3eb4ea60b7445bf70476cd178c891fc19cbc6f
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 700447b17c64668dec7457faf775c9a3a0534979d1cd4d82d8dfd49d8e8179509461d286bcdb7911d12966b30f162c5150c266d22bfaa495ee2174c0e56a7072
|
|
7
|
+
data.tar.gz: 83e5766101c0253074ee6255ac897adfe189831338183ba187268670b3a51531609098cfd275a6ed0a303757986241a97e49db10064dfbde7add215b4181b6b1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
ietfbib (0.4.0)
|
|
5
|
+
iso-bib-item (~> 0.3.0)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
byebug (10.0.2)
|
|
11
|
+
coderay (1.1.2)
|
|
12
|
+
diff-lcs (1.3)
|
|
13
|
+
docile (1.3.1)
|
|
14
|
+
equivalent-xml (0.6.0)
|
|
15
|
+
nokogiri (>= 1.4.3)
|
|
16
|
+
iso-bib-item (0.3.0)
|
|
17
|
+
isoics (~> 0.1.6)
|
|
18
|
+
nokogiri (~> 1.8.4)
|
|
19
|
+
ruby_deep_clone (~> 0.8.0)
|
|
20
|
+
isoics (0.1.7)
|
|
21
|
+
json (2.1.0)
|
|
22
|
+
method_source (0.9.0)
|
|
23
|
+
mini_portile2 (2.3.0)
|
|
24
|
+
nokogiri (1.8.4)
|
|
25
|
+
mini_portile2 (~> 2.3.0)
|
|
26
|
+
pry (0.11.3)
|
|
27
|
+
coderay (~> 1.1.0)
|
|
28
|
+
method_source (~> 0.9.0)
|
|
29
|
+
pry-byebug (3.6.0)
|
|
30
|
+
byebug (~> 10.0)
|
|
31
|
+
pry (~> 0.10)
|
|
32
|
+
rake (10.5.0)
|
|
33
|
+
rspec (3.8.0)
|
|
34
|
+
rspec-core (~> 3.8.0)
|
|
35
|
+
rspec-expectations (~> 3.8.0)
|
|
36
|
+
rspec-mocks (~> 3.8.0)
|
|
37
|
+
rspec-core (3.8.0)
|
|
38
|
+
rspec-support (~> 3.8.0)
|
|
39
|
+
rspec-expectations (3.8.1)
|
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
41
|
+
rspec-support (~> 3.8.0)
|
|
42
|
+
rspec-mocks (3.8.0)
|
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
44
|
+
rspec-support (~> 3.8.0)
|
|
45
|
+
rspec-support (3.8.0)
|
|
46
|
+
ruby_deep_clone (0.8.0)
|
|
47
|
+
simplecov (0.16.1)
|
|
48
|
+
docile (~> 1.1)
|
|
49
|
+
json (>= 1.8, < 3)
|
|
50
|
+
simplecov-html (~> 0.10.0)
|
|
51
|
+
simplecov-html (0.10.2)
|
|
52
|
+
|
|
53
|
+
PLATFORMS
|
|
54
|
+
ruby
|
|
55
|
+
|
|
56
|
+
DEPENDENCIES
|
|
57
|
+
bundler (~> 1.16)
|
|
58
|
+
equivalent-xml (~> 0.6)
|
|
59
|
+
ietfbib!
|
|
60
|
+
pry-byebug
|
|
61
|
+
rake (~> 10.0)
|
|
62
|
+
rspec (~> 3.0)
|
|
63
|
+
simplecov
|
|
64
|
+
|
|
65
|
+
BUNDLED WITH
|
|
66
|
+
1.16.2
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
BSD 2-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018, Ribose
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
* Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
20
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
21
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
22
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
23
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
24
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
25
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.adoc
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
= ietfbib
|
|
2
|
+
|
|
3
|
+
image:https://img.shields.io/gem/v/rfcbib.svg["Gem Version", link="https://rubygems.org/gems/rfcbib"]
|
|
4
|
+
image:https://img.shields.io/travis/riboseinc/rfcbib/master.svg["Build Status", link="https://travis-ci.org/riboseinc/rfcbib"]
|
|
5
|
+
image:https://codeclimate.com/github/riboseinc/rfcbib/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/riboseinc/rfcbib"]
|
|
6
|
+
|
|
7
|
+
_Formerly known as_ `rfcbib`.
|
|
8
|
+
|
|
9
|
+
ietfbib is a Ruby gem that search and fetch standards from the https://www.ietf.org[Internet Engineering Task Force (IETF)], including RFCs.
|
|
10
|
+
|
|
11
|
+
The standards scrape form https://www.rfc-editor.org/search/rfc_search.php
|
|
12
|
+
|
|
13
|
+
== Installation
|
|
14
|
+
|
|
15
|
+
Add this line to your application's Gemfile:
|
|
16
|
+
|
|
17
|
+
[source, ruby]
|
|
18
|
+
----
|
|
19
|
+
gem 'ietfbib'
|
|
20
|
+
----
|
|
21
|
+
|
|
22
|
+
And then execute:
|
|
23
|
+
|
|
24
|
+
$ bundle
|
|
25
|
+
|
|
26
|
+
Or install it yourself as:
|
|
27
|
+
|
|
28
|
+
$ gem install ietfbib
|
|
29
|
+
|
|
30
|
+
== Usage
|
|
31
|
+
|
|
32
|
+
=== Search document
|
|
33
|
+
|
|
34
|
+
[source,ruby]
|
|
35
|
+
----
|
|
36
|
+
item = IETFBib::RfcBibliography.search 'RFC 8341'
|
|
37
|
+
=> #<IsoBibItem::BibliographicItem:0x007fdb0803a0f8>
|
|
38
|
+
|
|
39
|
+
# Return nil if document doesn't exist.
|
|
40
|
+
IETFBib::RfcBibliography.search '1111'
|
|
41
|
+
=> nil
|
|
42
|
+
----
|
|
43
|
+
|
|
44
|
+
=== Serialization
|
|
45
|
+
|
|
46
|
+
[source,ruby]
|
|
47
|
+
----
|
|
48
|
+
item.to_xml
|
|
49
|
+
=>"<bibitem id='RFC8341'>
|
|
50
|
+
<title format='plain' language='en' script='Latn'>Network Configuration Access Control Model</title>
|
|
51
|
+
<link type='src'>https://www.rfc-editor.org/info/rfc8341</link>
|
|
52
|
+
<date type='published'>
|
|
53
|
+
<on>2018</on>
|
|
54
|
+
</date>
|
|
55
|
+
<contributor>
|
|
56
|
+
<role type='author'/>
|
|
57
|
+
<person>
|
|
58
|
+
<name>
|
|
59
|
+
<completename language='en'>A. Bierman</completename>
|
|
60
|
+
</name>
|
|
61
|
+
<affilation>
|
|
62
|
+
<organization>
|
|
63
|
+
<name/>
|
|
64
|
+
<abbreviation>IETF</abbreviation>
|
|
65
|
+
</organization>
|
|
66
|
+
</affilation>
|
|
67
|
+
</person>
|
|
68
|
+
</contributor>
|
|
69
|
+
<contributor>
|
|
70
|
+
<role type='author'/>
|
|
71
|
+
<person>
|
|
72
|
+
<name>
|
|
73
|
+
<completename language='en'>M. Bjorklund</completename>
|
|
74
|
+
</name>
|
|
75
|
+
<affilation>
|
|
76
|
+
<organization>
|
|
77
|
+
<name/>
|
|
78
|
+
<abbreviation>IETF</abbreviation>
|
|
79
|
+
</organization>
|
|
80
|
+
</affilation>
|
|
81
|
+
</person>
|
|
82
|
+
</contributor>
|
|
83
|
+
<language>en</language>
|
|
84
|
+
</bibitem>"
|
|
85
|
+
----
|
|
86
|
+
|
|
87
|
+
== Contributing
|
|
88
|
+
|
|
89
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ietfbib.
|
|
90
|
+
|
|
91
|
+
== License
|
|
92
|
+
|
|
93
|
+
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 "rfcbib"
|
|
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
data/ietfbib.gemspec
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require 'ietfbib/version'
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = 'ietfbib'
|
|
9
|
+
spec.version = IETFBib::VERSION
|
|
10
|
+
spec.authors = ['Ribose Inc.']
|
|
11
|
+
spec.email = ['open.source@ribose.com']
|
|
12
|
+
|
|
13
|
+
spec.summary = 'ietfbib: retrieve IETF Standards for bibliographic use '\
|
|
14
|
+
'using the BibliographicItem model'
|
|
15
|
+
spec.description = <<~DESCRIPTION
|
|
16
|
+
ietfbib: retrieve IETF Standards for bibliographic use
|
|
17
|
+
using the BibliographicItem model.
|
|
18
|
+
|
|
19
|
+
Formerly known as rfcbib.
|
|
20
|
+
DESCRIPTION
|
|
21
|
+
spec.homepage = 'https://github.com/riboseinc/ietfbib'
|
|
22
|
+
spec.license = 'BSD-2-Clause'
|
|
23
|
+
|
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
25
|
+
f.match(%r{^(test|spec|features)/})
|
|
26
|
+
end
|
|
27
|
+
spec.bindir = 'exe'
|
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
29
|
+
spec.require_paths = ['lib']
|
|
30
|
+
|
|
31
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
|
32
|
+
spec.add_development_dependency 'equivalent-xml', '~> 0.6'
|
|
33
|
+
spec.add_development_dependency 'pry-byebug'
|
|
34
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
36
|
+
spec.add_development_dependency 'simplecov'
|
|
37
|
+
|
|
38
|
+
spec.add_dependency 'iso-bib-item', '~> 0.3.0'
|
|
39
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal:true
|
|
2
|
+
|
|
3
|
+
require 'ietfbib/scrapper'
|
|
4
|
+
|
|
5
|
+
module IETFBib
|
|
6
|
+
# RFC bibliography module
|
|
7
|
+
module RfcBibliography
|
|
8
|
+
class << self
|
|
9
|
+
# @param code [String] the ISO standard Code to look up (e..g "ISO 9000")
|
|
10
|
+
# @return [IsoBibItem::BibliographicItem]
|
|
11
|
+
def search(text)
|
|
12
|
+
Scrapper.scrape_page text
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# @param code [String] the ISO standard Code to look up (e..g "ISO 9000")
|
|
16
|
+
# @param year [String] the year the standard was published (optional)
|
|
17
|
+
# @param opts [Hash] options; restricted to :all_parts if all-parts reference is required
|
|
18
|
+
# @return [IsoBibItem::BibliographicItem] Relaton of reference
|
|
19
|
+
def get(code, _year, _opts)
|
|
20
|
+
search code
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'net/http'
|
|
4
|
+
require 'nokogiri'
|
|
5
|
+
require 'iso_bib_item'
|
|
6
|
+
|
|
7
|
+
module IETFBib
|
|
8
|
+
# rubocop:disable Metrics/ModuleLength
|
|
9
|
+
|
|
10
|
+
# Scrapper module
|
|
11
|
+
module Scrapper
|
|
12
|
+
|
|
13
|
+
RFC_URI_PATTERN = "https://www.rfc-editor.org/refs/bibxml/reference.CODE"
|
|
14
|
+
ID_URI_PATTERN = "https://xml2rfc.tools.ietf.org/public/rfc/bibxml-ids/reference.CODE"
|
|
15
|
+
|
|
16
|
+
class << self
|
|
17
|
+
# @param text [String]
|
|
18
|
+
# @return [IsoBibItem::BibliographicItem]
|
|
19
|
+
def scrape_page(text)
|
|
20
|
+
|
|
21
|
+
# Remove initial "IETF " string if specified
|
|
22
|
+
ref = text.
|
|
23
|
+
gsub(/^IETF /, "").
|
|
24
|
+
sub(' ', '.') + '.xml'
|
|
25
|
+
|
|
26
|
+
uri = case ref
|
|
27
|
+
when /^RFC/
|
|
28
|
+
RFC_URI_PATTERN.dup
|
|
29
|
+
when /^I-D/
|
|
30
|
+
ID_URI_PATTERN.dup
|
|
31
|
+
else
|
|
32
|
+
warn "#{ref}: not recognised for RFC"
|
|
33
|
+
return
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
uri = uri.gsub("CODE", ref)
|
|
37
|
+
res = Net::HTTP.get_response(URI(uri))
|
|
38
|
+
if res.code != "200"
|
|
39
|
+
warn "No document found at #{uri}"
|
|
40
|
+
return
|
|
41
|
+
end
|
|
42
|
+
doc = Nokogiri::HTML Net::HTTP.get(URI(uri))
|
|
43
|
+
@reference = doc.at('//reference')
|
|
44
|
+
return unless @reference
|
|
45
|
+
bib_item
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
# rubocop:disable Metrics/MethodLength
|
|
51
|
+
|
|
52
|
+
# @return [IsoBibItem::BibliographicItem]
|
|
53
|
+
def bib_item
|
|
54
|
+
IsoBibItem::BibliographicItem.new(
|
|
55
|
+
id: @reference[:anchor],
|
|
56
|
+
docid: docids(@reference[:anchor].sub(/^(RFC)/, "\\1 ")),
|
|
57
|
+
status: status,
|
|
58
|
+
language: [language],
|
|
59
|
+
link: [{ type: 'src', content: @reference[:target] }],
|
|
60
|
+
titles: titles,
|
|
61
|
+
contributors: contributors,
|
|
62
|
+
dates: dates,
|
|
63
|
+
series: series
|
|
64
|
+
)
|
|
65
|
+
end
|
|
66
|
+
# rubocop:enable Metrics/MethodLength
|
|
67
|
+
|
|
68
|
+
# @return [String]
|
|
69
|
+
def language
|
|
70
|
+
@reference[:lang] || 'en'
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# @return [Array<Hash>]
|
|
74
|
+
def titles
|
|
75
|
+
title = @reference.at('//front/title')
|
|
76
|
+
[{ content: title.text, language: language, script: 'Latn' }]
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# @return [Array<Hash>]
|
|
80
|
+
def contributors
|
|
81
|
+
persons + organizations
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# @return [Array<Hash{Symbol=>IsoBibItem::Person,Symbol=>Array<String>}>]
|
|
85
|
+
def persons
|
|
86
|
+
@reference.xpath('//front/author').map do |author|
|
|
87
|
+
entity = IsoBibItem::Person.new(
|
|
88
|
+
name: full_name(author),
|
|
89
|
+
affiliation: [affiliation(author)],
|
|
90
|
+
contacts: contacts(author.at('//address'))
|
|
91
|
+
)
|
|
92
|
+
{ entity: entity, roles: [contributor_role(author)] }
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# @return [Array<Hash{Symbol=>IsoBibItem::Organization,Symbol=>Array<String>}>]
|
|
97
|
+
def organizations
|
|
98
|
+
@reference.xpath('//seriesinfo').map do |si|
|
|
99
|
+
next unless si[:stream]
|
|
100
|
+
entity = IsoBibItem::Organization.new name: si[:stream]
|
|
101
|
+
{ entity: entity, roles: ['author'] }
|
|
102
|
+
end.compact
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# @param author [Nokogiri::XML::Document]
|
|
106
|
+
# @return [IsoBibItem::FullName]
|
|
107
|
+
def full_name(author)
|
|
108
|
+
IsoBibItem::FullName.new(
|
|
109
|
+
completename: localized_string(author[:fullname]),
|
|
110
|
+
initials: [localized_string(author[:initials])],
|
|
111
|
+
surname: [localized_string(author[:surname])]
|
|
112
|
+
)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# @param content [String]
|
|
116
|
+
# @return [IsoBibItem::LocalizedString]
|
|
117
|
+
def localized_string(content)
|
|
118
|
+
IsoBibItem::LocalizedString.new(content, language)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# @param postal [Nokogiri::XML::Document]
|
|
122
|
+
# @return [Array<IsoBibItem::Address, IsoBibItem::Phone>]
|
|
123
|
+
def contacts(addr)
|
|
124
|
+
contacts = []
|
|
125
|
+
return contacts unless addr
|
|
126
|
+
postal = addr.at('//postal')
|
|
127
|
+
contacts << address(postal) if postal
|
|
128
|
+
add_contact(contacts, 'phone', addr.at('//phone'))
|
|
129
|
+
add_contact(contacts, 'email', addr.at('//email'))
|
|
130
|
+
add_contact(contacts, 'uri', addr.at('//uri'))
|
|
131
|
+
contacts
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# @param postal [Nokogiri::XML::Document]
|
|
135
|
+
# @rerurn [IsoBibItem::Address]
|
|
136
|
+
def address(postal)
|
|
137
|
+
IsoBibItem::Address.new(
|
|
138
|
+
street: [(postal.at('//postalLine') || postal.at('//street')).text],
|
|
139
|
+
city: postal.at('//city').text,
|
|
140
|
+
postcode: postal.at('//code').text,
|
|
141
|
+
country: postal.at('//country').text,
|
|
142
|
+
state: postal.at('//region').text
|
|
143
|
+
)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# @param type [String] allowed "phone", "email" or "uri"
|
|
147
|
+
# @param value [String]
|
|
148
|
+
def add_contact(contacts, type, value)
|
|
149
|
+
return unless value
|
|
150
|
+
contacts << IsoBibItem::Contact.new(type: type, value: value.text)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# @param author [Nokogiri::XML::Document]
|
|
154
|
+
# @return [IsoBibItem::Affilation]
|
|
155
|
+
def affiliation(author)
|
|
156
|
+
organization = author.at('//organization')
|
|
157
|
+
IsoBibItem::Affilation.new IsoBibItem::Organization.new(
|
|
158
|
+
name: organization.text.empty? ? 'IETF' : organization.text,
|
|
159
|
+
abbreviation: organization[:abbrev] || 'IETF'
|
|
160
|
+
)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# @param author [Nokogiri::XML::Document]
|
|
164
|
+
# @return [String]
|
|
165
|
+
def contributor_role(author)
|
|
166
|
+
author[:role] || 'author'
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def month(mo)
|
|
170
|
+
return mo if /^\d+$/.match mo
|
|
171
|
+
Date::MONTHNAMES.index(mo)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
#
|
|
175
|
+
# Extract date from reference.
|
|
176
|
+
#
|
|
177
|
+
# @return [Array<IsoBibItem::BibliographicDate>] published data.
|
|
178
|
+
#
|
|
179
|
+
def dates
|
|
180
|
+
return unless (date = @reference.at '//front/date')
|
|
181
|
+
d = [date[:year], month(date[:month]),
|
|
182
|
+
(date[:day] || "01")].compact.join '-'
|
|
183
|
+
date = Time.parse(d).strftime '%Y-%m-%d'
|
|
184
|
+
[IsoBibItem::BibliographicDate.new(type: 'published', on: date)]
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
#
|
|
188
|
+
# Extract document identifiers from reference
|
|
189
|
+
#
|
|
190
|
+
# @return [Array<IsoBibItem::DocumentIdentifier>]
|
|
191
|
+
#
|
|
192
|
+
def docids(id)
|
|
193
|
+
ret = []
|
|
194
|
+
ret << IsoBibItem::DocumentIdentifier.new(type: "IETF", id: id)
|
|
195
|
+
ret = ret + @reference.xpath('//seriesinfo').map do |si|
|
|
196
|
+
next unless si[:name] == 'DOI'
|
|
197
|
+
IsoBibItem::DocumentIdentifier.new(id: si[:value], type: si[:name])
|
|
198
|
+
end.compact
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
#
|
|
202
|
+
# Extract series form reference
|
|
203
|
+
#
|
|
204
|
+
# @return [Array<IsoBibItem::FormattedString>]
|
|
205
|
+
#
|
|
206
|
+
def series
|
|
207
|
+
@reference.xpath('//seriesinfo').map do |si|
|
|
208
|
+
next if si[:name] == 'DOI' || si[:stream] || si[:status]
|
|
209
|
+
IsoBibItem::Series.new(
|
|
210
|
+
title: IsoBibItem::FormattedString.new(
|
|
211
|
+
content: si[:name], language: language, script: 'Latn'
|
|
212
|
+
),
|
|
213
|
+
number: si[:value],
|
|
214
|
+
type: "main"
|
|
215
|
+
)
|
|
216
|
+
end.compact
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
#
|
|
220
|
+
# extract status
|
|
221
|
+
#
|
|
222
|
+
# @return [IsoBibItem::DocumentStatus]
|
|
223
|
+
#
|
|
224
|
+
def status
|
|
225
|
+
st = @reference.at('//seriesinfo[@status]')
|
|
226
|
+
return unless st
|
|
227
|
+
IsoBibItem::DocumentStatus.new(
|
|
228
|
+
IsoBibItem::LocalizedString.new(st[:status])
|
|
229
|
+
)
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
# rubocop:enable Metrics/ModuleLength
|
|
234
|
+
end
|
data/lib/ietfbib.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'relaton/processor'
|
|
2
|
+
|
|
3
|
+
module Relaton
|
|
4
|
+
module IETFBib
|
|
5
|
+
class Processor < Relaton::Processor
|
|
6
|
+
def initialize
|
|
7
|
+
@short = :rfcbib
|
|
8
|
+
@prefix = "IETF"
|
|
9
|
+
@defaultprefix = /^RFC /
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def get(code, date, opts)
|
|
13
|
+
::IETFBib::RfcBibliography.get(code, date, opts)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ietfbib
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.4.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ribose Inc.
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-09-09 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: '1.16'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.16'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: equivalent-xml
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0.6'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0.6'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: pry-byebug
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
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: simplecov
|
|
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: iso-bib-item
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: 0.3.0
|
|
104
|
+
type: :runtime
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: 0.3.0
|
|
111
|
+
description: "ietfbib: retrieve IETF Standards for bibliographic use \nusing the BibliographicItem
|
|
112
|
+
model.\n\nFormerly known as rfcbib.\n"
|
|
113
|
+
email:
|
|
114
|
+
- open.source@ribose.com
|
|
115
|
+
executables: []
|
|
116
|
+
extensions: []
|
|
117
|
+
extra_rdoc_files: []
|
|
118
|
+
files:
|
|
119
|
+
- ".gitignore"
|
|
120
|
+
- ".rspec"
|
|
121
|
+
- ".rubocop.yml"
|
|
122
|
+
- ".travis.yml"
|
|
123
|
+
- Gemfile
|
|
124
|
+
- Gemfile.lock
|
|
125
|
+
- LICENSE.txt
|
|
126
|
+
- README.adoc
|
|
127
|
+
- Rakefile
|
|
128
|
+
- bin/console
|
|
129
|
+
- bin/setup
|
|
130
|
+
- ietfbib.gemspec
|
|
131
|
+
- lib/ietfbib.rb
|
|
132
|
+
- lib/ietfbib/rfc_bibliography.rb
|
|
133
|
+
- lib/ietfbib/scrapper.rb
|
|
134
|
+
- lib/ietfbib/version.rb
|
|
135
|
+
- lib/relaton/processor.rb
|
|
136
|
+
homepage: https://github.com/riboseinc/ietfbib
|
|
137
|
+
licenses:
|
|
138
|
+
- BSD-2-Clause
|
|
139
|
+
metadata: {}
|
|
140
|
+
post_install_message:
|
|
141
|
+
rdoc_options: []
|
|
142
|
+
require_paths:
|
|
143
|
+
- lib
|
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
|
+
requirements:
|
|
146
|
+
- - ">="
|
|
147
|
+
- !ruby/object:Gem::Version
|
|
148
|
+
version: '0'
|
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
|
+
requirements:
|
|
151
|
+
- - ">="
|
|
152
|
+
- !ruby/object:Gem::Version
|
|
153
|
+
version: '0'
|
|
154
|
+
requirements: []
|
|
155
|
+
rubyforge_project:
|
|
156
|
+
rubygems_version: 2.7.6
|
|
157
|
+
signing_key:
|
|
158
|
+
specification_version: 4
|
|
159
|
+
summary: 'ietfbib: retrieve IETF Standards for bibliographic use using the BibliographicItem
|
|
160
|
+
model'
|
|
161
|
+
test_files: []
|