relaton / relaton-w3c

MIT License
2 stars 1 forks source link

= RelatonW3c

RelatonW3c is a Ruby gem that implements the https://github.com/metanorma/metanorma-model-iso#iso-bibliographic-item[IsoBibliographicItem model].

You can use it to retrieve metadata of W3C Standards from https://w3.org, and access such metadata through the W3cBibliographicItem object.

== Installation

Add this line to your application's Gemfile:

[source,ruby]

gem 'relaton-w3c'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install relaton-w3c

== Usage

=== Search for a standard using keywords

[source,ruby]

require 'relaton_w3c' => true

item = RelatonW3c::W3cBibliography.get "W3C REC-json-ld11-20200716" [relaton-w3c] (W3C REC-json-ld11-20200716) Fetching from Relaton repository ... [relaton-w3c] (W3C REC-json-ld11-20200716) Found: REC-json-ld11-20200716 => #<RelatonW3c::W3cBibliographicItem:0x00007fc4ea03c6c0 ...

=== XML serialization

[source,ruby]

item.to_xml => "

2022-12-05
  <title format="text/plain">JSON-LD 1.1</title>
  <uri type="src">https://www.w3.org/TR/2020/REC-json-ld11-20200716/</uri>
  ..
</bibitem>"

With argument bibdata: true it outputs XML wrapped by bibdata element and adds flavor ext element.

[source,ruby]

item.to_xml bibdata: true => "

2022-12-05
  <title format="text/plain">JSON-LD 1.1</title>
  <uri type="src">https://www.w3.org/TR/2020/REC-json-ld11-20200716/</uri>
  ...
  <ext schema-version="v1.0.0">
    <doctype>technicalReport</doctype>
    <editorialgroup>
      <technical-committee>JSON-LD Working Group</technical-committee>
    </editorialgroup>
  </ext>
</bibdata>"

=== Typed links

Each W3C document has src type link.

[source,ruby]

item.link.first.type => "src"

item.link.first.content => #<Addressable::URI:0x75634 URI:https://www.w3.org/TR/2020/REC-json-ld11-20200716/>

=== Create bibliographic item from XML [source,ruby]

RelatonW3c::XMLParser.from_xml File.read('spec/fixtures/cr_json_ld11.xml') => #<RelatonW3c::W3cBibliographicItem:0x007f9381efce98 ...

=== Create bibliographic item from YAML [source,ruby]

hash = YAML.load_file 'spec/fixtures/cr_json_ld11.yml' => {"schema-version"=>"v1.2.1", ...

bib_hash = RelatonW3c::HashConverter.hash_to_bib hash => {:"schema-version"=>"v1.2.1", ...

RelatonW3c::W3cBibliographicItem.new **bib_hash => #<RelatonW3c::W3cBibliographicItem:0x007f9381ec6a00 ...

=== Fetch data

The method RelatonW3c::DataFetcher.fetch(source, output: "data", format: "yaml") converts all the documents from the dataset and saves them to the ./data folder in YAML format. Arguments:

The available datasets are:

[source,ruby]

RelatonW3c::DataFetcher.fetch Started at: 2021-11-19 13:32:05 +0100 Stopped at: 2021-11-19 13:34:40 +0100 Done in: 155 sec. => nil

=== 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 https://github.com/relaton/relaton-logger#usage[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 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.

== 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.