README.adoc
= RelatonItu: retrieve ITU Standards for bibliographic use using the BibliographicItem model
image:https://img.shields.io/gem/v/relaton-itu.svg["Gem Version", link="https://rubygems.org/gems/relaton-itu"]
image:https://github.com/relaton/relaton-itu/workflows/macos/badge.svg["Build Status (macOS)", link="https://github.com/relaton/relaton-itu/actions?workflow=macos"]
image:https://github.com/relaton/relaton-itu/workflows/windows/badge.svg["Build Status (Windows)", link="https://github.com/relaton/relaton-itu/actions?workflow=windows"]
image:https://github.com/relaton/relaton-itu/workflows/ubuntu/badge.svg["Build Status (Ubuntu)", link="https://github.com/relaton/relaton-itu/actions?workflow=ubuntu"]
image:https://codeclimate.com/github/relaton/relaton-itu/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/relaton/relaton-itu"]
image:https://img.shields.io/github/issues-pr-raw/relaton/relaton-itu.svg["Pull Requests", link="https://github.com/relaton/relaton-itu/pulls"]
image:https://img.shields.io/github/commits-since/relaton/relaton-itu/latest.svg["Commits since latest",link="https://github.com/relaton/relaton-itu/releases"]
RelatonItu is a Ruby gem that implements the https://github.com/metanorma/metanorma-model-iso#iso-bibliographic-item[IsoBibliographicItem model].
== Installation
Add this line to your application's Gemfile:
[source,ruby]
----
gem 'relaton-bib'
----
And then execute:
$ bundle
Or install it yourself as:
$ gem install relaton-bib
== Usage
=== Configuration
Configuration is optional. The available option is `logger` which is a `Logger` instance. By default, the logger is `Logger.new($stderr)` with `Logger::WARN` level. To change the logger level, use `RelatonItu.configure` block.
[source,ruby]
----
require 'relaton_itu'
=> true
RelatonItu.configure do |config|
config.logger.level = Logger::DEBUG
end
----
=== Search for a standard using keywords
[source,ruby]
----
hit_collection = RelatonItu::ItuBibliography.search("ITU-T L.163")
=> <RelatonItu::HitCollection:0x007fbf5fb4ab60 @ref=ITU-T L.163 @fetched=false>
item = hit_collection[1].fetch
=> #<RelatonItu::ItuBibliographicItem:0x007fbf1fc89548
...
----
=== XML serialization
[source,ruby]
----
item.to_xml
=> "<bibitem id="ITU-TLSuppl.39" type="standard" schema-version="v1.2.1">
<fetched>2022-12-05</fetched>
<title type="title-intro" format="text/plain" language="en" script="Latn">ITU-T L.1470</title>
...
</bibitem>"
----
With `bibdata: true` option XML output is wrapped with `bibdata` element and `ext` element added.
[source,ruby]
----
item.to_xml bibdata: true
=> "<bibdata type="standard" schema-version="v1.2.1">
<fetched>2022-12-05</fetched>
<title type="title-intro" format="text/plain" language="en" script="Latn">ITU-T L.1470</title>
...
<ext schema-version="v1.0.0">
<doctype>recommendation</doctype>
...
</ext>
</bibdata>"
----
=== Get document by code and year
[source,ruby]
----
RelatonItu::ItuBibliography.get("ITU-T L.163", "2018", {})
[relaton-itu] (ITU-T L.163) Fetching from www.itu.int ...
[relaton-itu] (ITU-T L.163) Found: `ITU-T L.163`
=> #<RelatonItu::ItuBibliographicItem:0x007fbf5f94b9b8
...
----
=== Get amendment
[source,ruby]
----
RelatonItu::ItuBibliography.get "ITU-T G.989.2/Amd 1"
[relaton-itu] (ITU-T G.989.2/Amd 1) Fetching from www.itu.int ...
[relaton-itu] (ITU-T G.989.2/Amd 1) Found: `ITU-T G.989.2/Amd 1`
=> #<RelatonItu::ItuBibliographicItem:0x007fe5409e5840
...
----
=== Get ITU-R documents
[source,ruby]
----
RelatonItu::ItuBibliography.get "ITU-R BO.600-1"
[relaton-itu] (ITU-R BO.600-1) Fetching from www.itu.int ...
[relaton-itu] (ITU-R BO.600-1) Found: `ITU-R BO.600-1`
=> #<RelatonItu::ItuBibliographicItem:0x00007fb0cf8a1308
...
----
=== Get ITU-R Radio Regulations (RR)
[source,ruby]
----
RelatonItu::ItuBibliography.get 'ITU-R RR (2020)'
[relaton-itu] (ITU-R RR) Fetching from www.itu.int ...
[relaton-itu] WARNING: Invalid doctype: `publication`
[relaton-itu] (ITU-R RR) Found: ITU-R RR
=> #<RelatonItu::ItuBibliographicItem:0x007fb4b55eb660
...
----
=== Typed links
Each ITU document has `src` type link and optional `obp` and `word` link types.
[source,ruby]
----
item.link
=> [#<RelatonBib::TypedUri:0x00007f82d665f530 @content=#<Addressable::URI:0xc170 URI:https://www.itu.int/ITU-T/recommendations/rec.aspx?rec=13786&lang=en>, @type="src">,
#<RelatonBib::TypedUri:0x00007f82d665f0f8 @content=#<Addressable::URI:0xc184 URI:https://www.itu.inthttp//handle.itu.int/11.1002/1000/13786-en?locatt=format:pdf&auth>, @type="obp">]
----
=== Create a bibliographic item from YAML
[source,ruby]
----
hash = YAML.load_file 'spec/examples/itu_bib_item.yml'
=> {"id"=>"ITU-T L.163 (11/2018)",
...
RelatonItu::ItuBibliographicItem.from_hash hash
=> #<RelatonItu::ItuBibliographicItem:0x007fd88ac02aa0
...
----
=== Fetch data
This gem uses the (https://extranet.itu.int/brdocsearch) dataset as a data source. +
The method `RelatonItu::DataFetcher.fetch(output: "data", format: "yaml")` fetches all the documents from the dataset and saves them to the `./data` folder in YAML format.
Arguments:
- `output` - folder to save documents (default 'data').
- `format` - the format in which the documents are saved. Possible formats are: `yaml`, `xml`, `bibxxml` (default `yaml`).
[source,ruby]
----
RelatonItu::DataFetcher.fetch output: "dir", format: "xml"
Started at: 2023-05-27 09:21:16 -0400
Stopped at: 2023-05-27 09:27:45 -0400
Done in: 390 sec.
=> nil
----
== Development
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.
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).
== Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/metanorma/relaton-bib.
== License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).