relaton / relaton-un

UnBib: retrieve UN documents for bibliographic use using the BibliographicItem model
MIT License
1 stars 0 forks source link

= Relaton for UN documents

RelatonCalconnect 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 Calconnect Standards from https://standards.calconnect.org, and access such metadata through the CcBibliographicItem object.

== Installation

Add this line to your application's Gemfile:

[source,ruby]

gem 'relaton-un'

And then execute:

$ bundle

Or install it yourself as:

$ gem install relaton-un

== Usage

=== Search for a standard using keywords

[source,ruby]

require 'relaton_un' => true

hits = RelatonUn::UnBibliography.search("TRADE/CEFACT/2004/32") => <RelatonUn::HitCollection:0x007fc4e6ec2018 @ref=TRADE/CEFACT/2004/32 @fetched=false>

item = hits[0].fetch => #<RelatonUn::UnBibliographicItem:0x007fc4e6ac3138 ...

=== XML serialization

[source,ruby]

item.to_xml => "

2022-12-05
  ...
</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
  ...
  <ext schema-version="v1.0.0">
    <editorialgroup>
      <committee>Committee on Trade</committee>
      <committee>Centre for Trade Facilitation and Electronic Business</committee>
    </editorialgroup>
    ...
  </ext>
</bibdata>"

=== Get code, and year [source,ruby]

RelatonUn::UnBibliography.get "UN TRADE/CEFACT/2004/32" [relaton-un] (UN TRADE/CEFACT/2004/32) Fetching from documents.un.org ... [relaton-un] (UN TRADE/CEFACT/2004/32) Found: TRADE/CEFACT/2004/32 => #<RelatonUn::UnBibliographicItem:0x007fdc5f1c3a20 ...

=== Typed links

UN documens may have pdf and word link types.

[source,ruby]

item.link => [#<RelatonBib::TypedUri:0x00007f81af368250 @content=#<Addressable::URI:0x9ec URI:https://documents-dds-ny.un.org/doc/UNDOC/GEN/G04/306/83/pdf/G0430683.pdf?OpenElement>, @type="pdf">,

<RelatonBib::TypedUri:0x00007f81af3630e8 @content=#<Addressable::URI:0xa00 URI:https://documents-dds-ny.un.org/doc/UNDOC/GEN/G04/306/83/doc/G0430683.DOC?OpenElement>, @type="word">]


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

RelatonUn::XMLParser.from_xml File.read('spec/fixtures/un_bib.xml') => #<RelatonUn::UnBibliographicItem:0x007fdc5e7ab678 ...

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

hash = YAML.load_file 'spec/fixtures/un_bib.yaml' => {"id"=>"TRADE/CEFACT/2004/32", ...

bib_hash = RelatonUn::HashConverter.hash_to_bib hash => {:id=>"TRADE/CEFACT/2004/32", ...

RelatonUn::UnBibliographicItem.new **bib_hash => #<RelatonUn::UnBibliographicItem:0x007fdc5e061908 ...

=== Logging

RelatonUn 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/calconnect/relaton_un.

== License

The gem is available as open source under the terms of the MIT License.