relaton / relaton-ccsds

Implement relaton-ccsds for www.ccsds.org Standards
1 stars 0 forks source link

= RelatonCcsds

RelatonCcsds is a Ruby gem that implements the https://github.com/relaton/relaton-models#bibliographic-item[BibliographicItem model].

You can use it to retrieve metadata of CCSDS Standards from https://public.ccsds.org/Publications/AllPubs.aspx, and access such metadata through the RelatonCcsds::BibliographicItem object.

== Installation

Add this line to your application's Gemfile:

[source,ruby]

gem 'relaton-ccsds'

And then execute:

$ bundle

Or install it yourself as:

$ gem install relaton-ccsds

== Usage

=== Search for a standard using keywords

[source,ruby]

require 'relaton_ccsds' => true

hits = RelatonCcsds::Bibliography.search("CCSDS 230.2-G-1") => <RelatonCcsds::HitCollection:0x00000000001770 @ref=CCSDS 230.2-G-1 @fetched=false>

item = hits[0].doc => #<RelatonCcsds::BibliographicItem:0x00000001135f6540 ...

=== XML serialization

[source,ruby]

item.to_xml => "

2023-08-25
  <title format="text/plain" language="en" script="Latn">Next Generation Uplink</title>
  <uri type="pdf">https://public.ccsds.org/Pubs/230x2g1.pdf</uri>
  <docidentifier type="CCSDS" primary="true">CCSDS 230.2-G-1</docidentifier>
  ...
</bibitem>"

With argument bibdata: true it outputs XML wrapped by bibdata element and adds flavour ext element. [source,ruby]

item.to_xml bibdata: true => "

2023-08-25
  <title format="text/plain" language="en" script="Latn">Next Generation Uplink</title>
  <uri type="pdf">https://public.ccsds.org/Pubs/230x2g1.pdf</uri>
  ...
  <ext>
    <doctype>report</doctype>
    <editorialgroup>
      <technical-committee>SLS-NGU</technical-committee>
    </editorialgroup>
    <technology-area>Space Link Services Area</technology-area>
  </ext>
</bibdata>"

=== Typed links

All the CCSDS documents have PDF links. Some of them have additional DOC links. The gem provides a way to access these links through the RelatonBib::TypedUri object.

[source,ruby]

item.link => [#<RelatonBib::TypedUri:0x000000011420d950 @content=#<Addressable::URI:0xc1c URI:https://public.ccsds.org/Pubs/230x2g1.pdf>, @language=nil, @script=nil, @type="pdf">]

RelatonCcsds::Bibliography.get("CCSDS 720.6-Y-1").link [relaton-ccsds] (CCSDS 720.6-Y-1) Fetching from Relaton repository ... [relaton-ccsds] (CCSDS 720.6-Y-1) Found: CCSDS 720.6-Y-1. => [#<RelatonBib::TypedUri:0x0000000114183bb0 @content=#<Addressable::URI:0xca8 URI:https://public.ccsds.org/Pubs/720x6y1.pdf>, @language=nil, @script=nil, @type="pdf">,

<RelatonBib::TypedUri:0x0000000114183750

@content=#<Addressable::URI:0xcbc URI:https://public.ccsds.org/Pubs/720x6y1.doc>, @language=nil, @script=nil, @type="doc">]

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

RelatonCcsds::Bibliography.get("CCSDS 230.2-G-1") [relaton-ccsds] (CCSDS 230.2-G-1) Fetching from Relaton repository ... [relaton-ccsds] (CCSDS 230.2-G-1) Found: CCSDS 230.2-G-1. => #<RelatonCcsds::BibliographicItem:0x00000001135dade0 ...

=== Get specific format

[source,ruby]

item = RelatonCcsds::Bibliography.get("CCSDS 720.4-Y-1 (DOC)") [relaton-ccsds] (CCSDS 720.4-Y-1 (DOC)) Fetching from Relaton repository ... [relaton-ccsds] (CCSDS 720.4-Y-1 (DOC)) Found: CCSDS 720.4-Y-1. => #<RelatonCcsds::BibliographicItem:0x000000011100dfe0 ...

item.link.size => 1

item.link[0].type => "doc"

pry(main)> item.link[0].content.to_s => "https://public.ccsds.org/Pubs/720x4y1.doc"

item = RelatonCcsds::Bibliography.get("CCSDS 720.4-Y-1 (PDF)") [relaton-ccsds] (CCSDS 720.4-Y-1 (PDF)) Fetching from Relaton repository ... [relaton-ccsds] (CCSDS 720.4-Y-1 (PDF)) Found: CCSDS 720.4-Y-1. => #<RelatonCcsds::BibliographicItem:0x0000000111004620 ...

item.link.size => 1

item.link[0].type => "pdf"

item.link[0].content.to_s => "https://public.ccsds.org/Pubs/720x4y1.pdf"

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

RelatonCcsds::XMLParser.from_xml File.read('spec/fixtures/ccsds_230_2-g-1.xml') => #<RelatonCcsds::BibliographicItem:0x00000001135fc1c0 ...

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

hash = YAML.load_file 'spec/fixtures/ccsds_230_2-g-1.yaml' => {"schema-version"=>"v1.2.4", "id"=>"CCSDS230.2-G-1", ...

RelatonCcsds::BibliographicItem.from_hash hash => #<RelatonCcsds::BibliographicItem:0x00000001135ff780 ...

=== Fetch data

This gem uses the https://public.ccsds.org/Publications/AllPubs.aspx as a data source.

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

[source,ruby]

RelatonCcsds::DataFetcher.fetch Started at: 2023-08-25 22:02:06 -0400 (data/CCSDS-720-4-Y-1.yaml) file already exists. Trying to merge links ... ... Done in: 20 sec. => nil

=== Logging

RelatonCcsds 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-ccsds.

== License

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