RelatonW3c is a Ruby gem that implements the IsoBibliographicItem model.
You can use it to retrieve metadata of W3C Standards from https://w3.org, and access such metadata through the Relaton::W3c::Item object.
Installation
Add this line to your application’s Gemfile:
gem 'relaton-w3c'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install relaton-w3c
Usage
Search for a standard using keywords
require 'relaton/w3c'
=> true
item = Relaton::W3c::Bibliography.get "W3C REC-json-ld11-20200716"
[relaton-w3c] INFO: (W3C REC-json-ld11-20200716) Fetching from Relaton repository ...
[relaton-w3c] INFO: (W3C REC-json-ld11-20200716) Found: `W3C REC-json-ld11-20200716`
=> #<Relaton::W3c::ItemData:0x0000000129b05b38
...
XML serialization
item.to_xml
=> "<bibitem id="W3CRECjsonld1120200716" type="standard" schema-version="v1.4.1">
<fetched>2026-03-04</fetched>
<formattedref>W3C REC-json-ld11-20200716</formattedref>
<title language="en" script="Latn">JSON-LD 1.1</title>
<uri type="src">https://www.w3.org/TR/2020/REC-json-ld11-20200716/</uri>
<docidentifier type="W3C" primary="true">W3C REC-json-ld11-20200716</docidentifier>
..
</bibitem>"
With argument bibdata: true it outputs XML wrapped by bibdata element and adds flavor ext element.
item.to_xml bibdata: true
=> "<bibdata type="standard" schema-version="v1.4.1">
<fetched>2026-03-04</fetched>
<formattedref>W3C REC-json-ld11-20200716</formattedref>
<title language="en" script="Latn">JSON-LD 1.1</title>
<uri type="src">https://www.w3.org/TR/2020/REC-json-ld11-20200716/</uri>
<docidentifier type="W3C" primary="true">W3C REC-json-ld11-20200716</docidentifier>
...
<ext schema-version="v1.0.0">
<doctype>technicalReport</doctype>
<flavor>w3c</flavor>
</ext>
</bibdata>"
Typed source links
Each W3C document has src type source link.
item.source.first.type
=> "src"
item.source.first.content
=> "https://www.w3.org/TR/2020/REC-json-ld11-20200716/"
Create bibliographic item from XML
Relaton::W3c::Bibdata.from_xml File.read('spec/fixtures/cr_json_ld11.xml')
=> #<Relaton::Bib::ItemData:0x0000000100f50018
...
Create bibliographic item from YAML
Relaton::W3c::Item.from_yaml File.read('spec/fixtures/item.yaml')
=> #<Relaton::W3c::ItemData:0x000000012b917450
...
Fetch data
The method Relaton::W3c::DataFetcher.fetch(output: "data", format: "yaml") converts all the documents from the W3C API 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,bibxml(defaultyaml).
The available dataset is:
- w3c-api - The dataset is fetched from the W3C API.
require 'relaton/w3c/data_fetcher'
Relaton::W3c::DataFetcher.fetch
Logging
RelatonW3c uses the relaton-logger gem for logging. By default, it logs to STDOUT. To change the log levels and add other loggers, read the relaton-logger documentation.
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 update the index test fixture (used by tests), run rake spec:update_index. This downloads the latest index-v1.zip from the relaton-data-w3c repository.
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/relaton/relaton_w3c.
License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).