relaton-xsf 1.14.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 57967099fd01cd6118a6af5300a6e64e02f4e9469dec76a856b6e34be6aa744e
4
+ data.tar.gz: b1d20c686eca06489fb63cc9e7a651c8fc58a36b0b86564587d259f78fff679a
5
+ SHA512:
6
+ metadata.gz: 159d02d559ae64e01e86be9b0742a2cf4b8c87a280146e8aa40152de5dbf70e92bba9fdc23b3ebd6586259b4862528f9343ede2ff3d5ccce11f8d5fb853201f0
7
+ data.tar.gz: 37014f915743509729b8d19aed0a0294ef0d9c7fadabd754fde0da0b6376f1bab0c2a36d8cb81e86d30b017f72904a1d4c4c05c70c3e5b78f930c94dea9fc9d5
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,12 @@
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
+ require: rubocop-rails
6
+
7
+ inherit_from:
8
+ - https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
9
+ AllCops:
10
+ TargetRubyVersion: 2.7
11
+ Rails:
12
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in relaton_xsf.gemspec
6
+ gemspec
7
+
8
+ gem "equivalent-xml", "~> 0.6"
9
+ gem "rake", "~> 13.0"
10
+ gem "rspec", "~> 3.0"
11
+ gem "rubocop", "~> 1.21"
12
+ gem "rubocop-performance", "~> 1.11"
13
+ gem "rubocop-rails", "~> 2.0"
14
+ gem "simplecov", "~> 0.22"
15
+ gem "vcr", "~> 6.0"
16
+ gem "webmock", "~> 3.0"
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,138 @@
1
+ = Relaton-XSF: bibliographic retrieval of XMPP XEP specifications
2
+
3
+ image:https://img.shields.io/gem/v/relaton-xsf.svg["Gem Version", link="https://rubygems.org/gems/relaton-xsf"]
4
+ image:https://github.com/relaton/relaton-xsf/workflows/macos/badge.svg["Build Status (macOS)", link="https://github.com/relaton/relaton-xsf/actions?workflow=macos"]
5
+ image:https://github.com/relaton/relaton-xsf/workflows/windows/badge.svg["Build Status (Windows)", link="https://github.com/relaton/relaton-xsf/actions?workflow=windows"]
6
+ image:https://github.com/relaton/relaton-xsf/workflows/ubuntu/badge.svg["Build Status (Ubuntu)", link="https://github.com/relaton/relaton-xsf/actions?workflow=ubuntu"]
7
+ image:https://codeclimate.com/github/relaton/relaton-xsf/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/relaton/relaton-xsf"]
8
+ image:https://img.shields.io/github/issues-pr-raw/relaton/relaton-xsf.svg["Pull Requests", link="https://github.com/relaton/relaton-xsf/pulls"]
9
+ image:https://img.shields.io/github/commits-since/relaton/relaton-xsf/latest.svg["Commits since latest",link="https://github.com/relaton/relaton-xsf/releases"]
10
+
11
+ == Purpose
12
+
13
+ `relaton-xsf` provides bibliographic information of XMPP XEP specifications using the
14
+ https://github.com/relaton/relaton-models#the-relaton-bibliographic-models[BibliographicItem model].
15
+
16
+ == Data sources
17
+
18
+ Relaton-XSF retrieves bibliographic information from https://xmpp.org/extensions/refs/[XMPP dataset].
19
+
20
+ The XSF Library dataset provides documents listed in the https://github.com/relaton/relaton-data-xsf/blob/main/index-v1.yaml[index].
21
+
22
+ == Installation
23
+
24
+ Add this line to your application's Gemfile:
25
+
26
+ [source,ruby]
27
+ ----
28
+ gem 'relaton-xsf'
29
+ ----
30
+
31
+ And then execute:
32
+
33
+ $ bundle
34
+
35
+ Or install it yourself as:
36
+
37
+ $ gem install relaton-xsf
38
+
39
+ == Usage
40
+
41
+ === Search for a standard using keywords
42
+
43
+ [source,ruby]
44
+ ----
45
+ require 'relaton_xsf'
46
+ => true
47
+
48
+ hit_collection = RelatonXsf::Bibliography.search("XEP 0001")
49
+ => <RelatonXsf::HitCollection:0x00000000019780 @ref=XEP 0001 @fetched=false>
50
+
51
+ item = hit_collection[0].fetch
52
+ => #<RelatonXsf::BibliographicItem:0x000000011167a518
53
+ ...
54
+ ----
55
+
56
+ === XML serialization
57
+ [source,ruby]
58
+ ----
59
+ item.to_xml
60
+ => "<bibitem id="XEP0001" type="standard" schema-version="v1.2.3">
61
+ <fetched>2023-07-18</fetched>
62
+ <title format="text/plain" language="en" script="Latn">XMPP Extension Protocols</title>
63
+ ...
64
+ <bibitem>"
65
+ ----
66
+ With argument `bibdata: true` it outputs XML wrapped by `bibdata` element and adds flavor `ext` element.
67
+ [source,ruby]
68
+ ----
69
+ item.to_xml bibdata: true
70
+ => "<bibdata type="standard" schema-version="v1.2.3">
71
+ <fetched>2023-07-18</fetched>
72
+ <title format="text/plain" language="en" script="Latn">XMPP Extension Protocols</title>
73
+ ...
74
+ <ext>
75
+ <doctype>rfc</doctype>
76
+ </ext>
77
+ </bibdata>"
78
+ ----
79
+
80
+ === Get document by reference
81
+ [source,ruby]
82
+ ----
83
+ item = RelatonXsf::Bibliography.get "XEP 0001"
84
+ [relaton-xsf] (XEP 0001) fetching...
85
+ [relaton-xsf] (XEP 0001) found XEP 0001
86
+ => #<RelatonXsf::BibliographicItem:0x000000011275cd18
87
+ ...
88
+
89
+ item.docidentifier.first.id
90
+ => "XEP 0001"
91
+ ----
92
+
93
+ === Typed links
94
+
95
+ XSF publications have `src` type link.
96
+
97
+ [source,ruby]
98
+ ----
99
+ item.link
100
+ => [#<RelatonBib::TypedUri:0x0000000113ad5ca0
101
+ @content=#<Addressable::URI:0xcc24 URI:http://xmpp.org/extensions/xep-0001.html>,
102
+ @language=nil,
103
+ @script=nil,
104
+ @type="src">]
105
+ ----
106
+
107
+ === Fetch data
108
+
109
+ This gem uses the https://xmpp.org/extensions/refs/ dataset as a data source.
110
+
111
+ The method `RelatonXsf::DataFetcher.fetch(output: "data", format: "yaml")` fetches all the documents from the dataset and saves them to the `./data` folder in YAML format.
112
+ Arguments:
113
+
114
+ - `output` - folder to save documents (default './data').
115
+ - `format` - the format in which the documents are saved. Possible formats are: `yaml`, `xml`, `bibxxml` (default `yaml`).
116
+
117
+ [source,ruby]
118
+ ----
119
+ RelatonXsf::DataFetcher.fetch
120
+ Started at: 2021-09-01 18:01:01 +0200
121
+ Stopped at: 2021-09-01 18:01:43 +0200
122
+ Done in: 42 sec.
123
+ => nil
124
+ ----
125
+
126
+ == Development
127
+
128
+ 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.
129
+
130
+ 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 https://rubygems.org[rubygems.org].
131
+
132
+ == Contributing
133
+
134
+ Bug reports and pull requests are welcome on GitHub at https://github.com/metanorma/relaton-xsf.
135
+
136
+ == License
137
+
138
+ The gem is available as open source under the terms of the https://opensource.org/license/bsd-2-clause/[2-Clause BSD License].
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec]
@@ -0,0 +1,4 @@
1
+ module RelatonXsf
2
+ class BibliographicItem < RelatonBib::BibliographicItem
3
+ end
4
+ end
@@ -0,0 +1,22 @@
1
+ module RelatonXsf
2
+ module Bibliography
3
+ extend self
4
+
5
+ def search(ref)
6
+ HitCollection.new(ref).search
7
+ end
8
+
9
+ def get(code, _year = nil, _opts = {})
10
+ warn "[relaton-xsf] (#{code}) fetching..."
11
+ result = search(code)
12
+ if result.empty?
13
+ warn "[relaton-xsf] (#{code}) nothing found"
14
+ return
15
+ end
16
+
17
+ bib = result.first.fetch
18
+ warn "[relaton-xsf] (#{code}) found #{bib.docidentifier.first.id}"
19
+ bib
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ module RelatonXsf
2
+ module BibXMLParser
3
+ include RelatonBib::BibXMLParser
4
+ extend self
5
+
6
+ # @param item_hash [Hash]
7
+ # @return [RelatonXsf::BibliographicItem]
8
+ def bib_item(item_hash)
9
+ BibliographicItem.new(**item_hash)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,57 @@
1
+ module RelatonXsf
2
+ class DataFetcher
3
+ # @param output [String]
4
+ # @param format [String]
5
+ def initialize(output, format)
6
+ @output = output
7
+ @format = format
8
+ @ext = format.sub(/^bib/, "")
9
+ @files = []
10
+ end
11
+
12
+ def self.fetch(output: "data", format: "yaml")
13
+ warn "[relaton-xsf] fetching data to #{output} in #{format} format"
14
+ t1 = Time.now
15
+ warn "[relaton-xsf] start at #{t1}"
16
+ FileUtils.mkdir_p output
17
+ new(output, format).fetch
18
+ t2 = Time.now
19
+ t = t2 - t1
20
+ warn "[relaton-xsf] finished at #{t2} (#{t.round} seconds)"
21
+ end
22
+
23
+ def index
24
+ @index ||= Relaton::Index.find_or_create :xsf, file: "index-v1.yaml"
25
+ end
26
+
27
+ def fetch
28
+ agent = Mechanize.new
29
+ resp = agent.get "https://xmpp.org/extensions/refs/"
30
+ resp.xpath("//a[contains(@href, 'XEP-')]").each do |link|
31
+ doc = agent.get link[:href]
32
+ bib = BibXMLParser.parse doc.body
33
+ write_doc bib
34
+ end
35
+ index.save
36
+ end
37
+
38
+ def write_doc(bib)
39
+ id = bib.docidentifier.find(&:primary).id
40
+ file = File.join @output, "#{id.gsub(' ', '-').downcase}.#{@ext}"
41
+ if @files.include? file
42
+ warn "[relaton-xsf] WARNING: #{file} already exists"
43
+ end
44
+ File.write file, serialize(bib), encoding: "UTF-8"
45
+ @files << file
46
+ index.add_or_update id, file
47
+ end
48
+
49
+ def serialize(bib)
50
+ case @format
51
+ when "yaml" then bib.to_hash.to_yaml
52
+ when "xml" then bib.to_xml bibdata: true
53
+ else bib.send "to_#{@format}"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,11 @@
1
+ module RelatonXsf
2
+ class HashConverter < RelatonBib::HashConverter
3
+ class << self
4
+ # @param item_hash [Hash]
5
+ # @return [RelatonBib::BibliographicItem]
6
+ def bib_item(item_hash)
7
+ BibliographicItem.new(**item_hash)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module RelatonXsf
2
+ class Hit < RelatonBib::Hit
3
+ def fetch
4
+ return @doc if @doc
5
+
6
+ agent = Mechanize.new
7
+ resp = agent.get hit[:url]
8
+ hash = YAML.safe_load resp.body
9
+ hash["fetched"] = Date.today.to_s
10
+ @doc = BibliographicItem.from_hash hash
11
+ rescue StandardError => e
12
+ raise RelatonBib::RequestError, e.message
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module RelatonXsf
2
+ class HitCollection < RelatonBib::HitCollection
3
+ INDEX_FILE = "index-v1.yaml".freeze
4
+ GHDATA_URL = "https://raw.githubusercontent.com/relaton/relaton-data-xsf/main/".freeze
5
+
6
+ def search
7
+ @array = index.search(text).sort_by { |hit| hit[:id] }.map do |row|
8
+ Hit.new url: "#{GHDATA_URL}#{row[:file]}"
9
+ end
10
+ self
11
+ rescue StandardError => e
12
+ raise RelatonBib::RequestError, e.message
13
+ end
14
+
15
+ def index
16
+ @index ||= Relaton::Index.find_or_create :xsf, url: "#{GHDATA_URL}index-v1.zip", file: INDEX_FILE
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,61 @@
1
+ require "relaton/processor"
2
+
3
+ module RelatonXsf
4
+ class Processor < Relaton::Processor
5
+ attr_reader :idtype
6
+
7
+ def initialize # rubocop:disable Lint/MissingSuper
8
+ @short = :relaton_xsf
9
+ @prefix = "XEP"
10
+ @defaultprefix = %r{^XEP\s}
11
+ @idtype = "XEP"
12
+ @datasets = %w[xep-xmpp]
13
+ end
14
+
15
+ # @param code [String]
16
+ # @param date [String, nil] year
17
+ # @param opts [Hash]
18
+ # @return [RelatonXsf::BibliographicItem]
19
+ def get(code, date, opts)
20
+ ::RelatonXsf::Bibliography.get(code, date, opts)
21
+ end
22
+
23
+ #
24
+ # Fetch all the documents from http://xml2rfc.tools.ietf.org/public/rfc/bibxml-3gpp-new/
25
+ #
26
+ # @param [String] source source name
27
+ # @param [Hash] opts
28
+ # @option opts [String] :output directory to output documents
29
+ # @option opts [String] :format
30
+ #
31
+ def fetch_data(_source, opts)
32
+ ::RelatonXsf::DataFetcher.fetch(**opts)
33
+ end
34
+
35
+ # @param xml [String]
36
+ # @return [RelatonXsf::BibliographicItem]
37
+ def from_xml(xml)
38
+ ::RelatonXsf::XMLParser.from_xml xml
39
+ end
40
+
41
+ # @param hash [Hash]
42
+ # @return [RelatonXsf::BibliographicItem]
43
+ def hash_to_bib(hash)
44
+ item_hash = ::RelatonXsf::HashConverter.hash_to_bib(hash)
45
+ ::RelatonXsf::BibliographicItem.new(**item_hash)
46
+ end
47
+
48
+ # Returns hash of XML grammar
49
+ # @return [String]
50
+ def grammar_hash
51
+ @grammar_hash ||= ::RelatonBib.grammar_hash
52
+ end
53
+
54
+ #
55
+ # Remove index file
56
+ #
57
+ def remove_index_file
58
+ Relaton::Index.find_or_create(:xsf, url: true, file: HitCollection::INDEX_FILE).remove_file
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RelatonXsf
4
+ VERSION = "1.14.0"
5
+ end
@@ -0,0 +1,14 @@
1
+ module RelatonXsf
2
+ class XMLParser < RelatonBib::XMLParser
3
+ #
4
+ # Create bibliographic item
5
+ #
6
+ # @param item_hash [Hash] bibliographic item hash
7
+ #
8
+ # @return [RelatonXsf::BibliographicItem] bibliographic item
9
+ #
10
+ def self.bib_item(item_hash)
11
+ BibliographicItem.new(**item_hash)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mechanize"
4
+ require "relaton/index"
5
+ require "relaton_bib"
6
+ require_relative "relaton_xsf/version"
7
+ require_relative "relaton_xsf/bibliographic_item"
8
+ require_relative "relaton_xsf/bibliography"
9
+ require_relative "relaton_xsf/hit_collection"
10
+ require_relative "relaton_xsf/hit"
11
+ require_relative "relaton_xsf/xml_parser"
12
+ require_relative "relaton_xsf/bibxml_parser"
13
+ require_relative "relaton_xsf/hash_converter"
14
+ require_relative "relaton_xsf/data_fetcher"
15
+
16
+ module RelatonXsf
17
+ class Error < StandardError; end
18
+ # Your code goes here...
19
+ end
@@ -0,0 +1,4 @@
1
+ module RelatonXsf
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: relaton-xsf
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.14.0
5
+ platform: ruby
6
+ authors:
7
+ - Ribose Inc.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-07-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mechanize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: relaton-bib
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.14.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.14.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: relaton-index
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.0
55
+ description: 'RelatonIso: retrieve ISO Standards for bibliographic use using the IsoBibliographicItem
56
+ model'
57
+ email:
58
+ - open.source@ribose.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".rspec"
64
+ - ".rubocop.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.adoc
68
+ - Rakefile
69
+ - lib/relaton_xsf.rb
70
+ - lib/relaton_xsf/bibliographic_item.rb
71
+ - lib/relaton_xsf/bibliography.rb
72
+ - lib/relaton_xsf/bibxml_parser.rb
73
+ - lib/relaton_xsf/data_fetcher.rb
74
+ - lib/relaton_xsf/hash_converter.rb
75
+ - lib/relaton_xsf/hit.rb
76
+ - lib/relaton_xsf/hit_collection.rb
77
+ - lib/relaton_xsf/processor.rb
78
+ - lib/relaton_xsf/version.rb
79
+ - lib/relaton_xsf/xml_parser.rb
80
+ - sig/relaton_xsf.rbs
81
+ homepage: https://github.com/relaton/relaton-xsf
82
+ licenses:
83
+ - BSD-2-Clause
84
+ metadata:
85
+ homepage_uri: https://github.com/relaton/relaton-xsf
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 2.7.0
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubygems_version: 3.3.26
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: 'RelatonIso: retrieve ISO Standards for bibliographic use using the IsoBibliographicItem
105
+ model'
106
+ test_files: []