relaton/relaton-ogc

View on GitHub
README.adoc

Summary

Maintainability
Test Coverage
= RelatonOgc

image:https://img.shields.io/gem/v/relaton-ogc.svg["Gem Version", link="https://rubygems.org/gems/relaton-ogc"]
image:https://github.com/relaton/relaton-ogc/workflows/macos/badge.svg["Build Status (macOS)", link="https://github.com/relaton/relaton-ogc/actions?workflow=macos"]
image:https://github.com/relaton/relaton-ogc/workflows/windows/badge.svg["Build Status (Windows)", link="https://github.com/relaton/relaton-ogc/actions?workflow=windows"]
image:https://github.com/relaton/relaton-ogc/workflows/ubuntu/badge.svg["Build Status (Ubuntu)", link="https://github.com/relaton/relaton-ogc/actions?workflow=ubuntu"]
image:https://codeclimate.com/github/relaton/relaton-ogc/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/relaton/relaton-ogc"]
image:https://img.shields.io/github/issues-pr-raw/relaton/relaton-ogc.svg["Pull Requests", link="https://github.com/relaton/relaton-ogc/pulls"]
image:https://img.shields.io/github/commits-since/relaton/relaton-ogc/latest.svg["Commits since latest",link="https://github.com/relaton/relaton-ogc/releases"]

RelatonOgc 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 OGC Standards from https://raw.githubusercontent.com/opengeospatial/NamingAuthority/master/incubation/bibliography/bibliography.json, and access such metadata through the `OgcBibliographicItem` object.

== Installation

Add this line to your application's Gemfile:

[source,ruby]
----
gem 'relaton-ogc'
----

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install relaton-ogc

== 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 `RelatonOgc.configure` block.

[source,ruby]
----
require 'relaton_ogc'
=> true

RelatonOgc.configure do |config|
  config.logger.level = Logger::DEBUG
end
----

=== Search for a standard using keywords

[source,ruby]
----
hits = RelatonOgc::OgcBibliography.search("OGC 19-025r1")
=> <RelatonOgc::HitCollection:0x007fcc8e085ba8 @ref=OGC 19-025r1 @fetched=true>

item = hits[0].fetch
=> #<RelatonOgc::OgcBibliographicItem:0x007fcab3cb4758
...
----

=== XML serialization
[source,ruby]
----
item.to_xml
=> "<bibitem id="19-025r1" type="standard" schema-version="v1.2.1">
      <fetched>2022-12-04</fetched>
      <title type="title-main" format="text/plain" language="en" script="Latn">Development of Spatial Data Infrastructures for Marine Data Management</title>
      <title type="main" format="text/plain" language="en" script="Latn">Development of Spatial Data Infrastructures for Marine Data Management</title>
      <uri type="obp">https://portal.ogc.org/files/?artifact_id=88037</uri>
      <docidentifier type="OGC" primary="true">19-025r1</docidentifier>
      ...
    </bibitem>"
----
With argument `bibdata: true` it outputs XML wrapped by `bibdata` element and adds flavor `ext` element.
[source,ruby]
----
item.to_xml bibdata: true
=> "<bibdata type="standard" schema-version="v1.2.1">
      <fetched>2022-12-04</fetched>
      <title type="title-main" format="text/plain" language="en" script="Latn">Development of Spatial Data Infrastructures for Marine Data Management</title>
      <title type="main" format="text/plain" language="en" script="Latn">Development of Spatial Data Infrastructures for Marine Data Management</title>
      <uri type="obp">https://portal.ogc.org/files/?artifact_id=88037</uri>
      <docidentifier type="OGC" primary="true">19-025r1</docidentifier>
      ...
      <ext schema-version="v1.0.1">
        <doctype>engineering-report</doctype>
        <editorialgroup>
          <committee>technical</committee>
        </editorialgroup>
      </ext>
    </bibdata>"
----

=== Get code, and year
[source,ruby]
----
RelatonOgc::OgcBibliography.get "OGC 19-025r1", "2019", {}
[relaton-ogc] (OGC 19-025r1) Fetching from Relaton repository ...
[relaton-ogc] (OGC 19-025r1) Found: `19-025r1`
=> #<RelatonOgc::OgcBibliographicItem:0x007fc322e9aba0
...
----

=== Create bibliographic item from XML
[source,ruby]
----
RelatonOgc::XMLParser.from_xml File.read('spec/fixtures/12_128r14.xml')
=> #<RelatonOgc::OgcBibliographicItem:0x00007fd2b1078718
...
----

=== Typed links

Each OGC document has `obp` type link.

[source,ruby]
----
item.link
=> [#<RelatonBib::TypedUri:0x00007fc848994568 @content=#<Addressable::URI:0x8e8 URI:https://portal.ogc.org/files/?artifact_id=88037>, @type="obp">]
----

=== Create bibliographic item from YAML
[source,ruby]
----
hash = YAML.load_file 'spec/fixtures/ogc_bib_item.yml'
=> {"id"=>"19-025r1",
...

RelatonOgc::OgcBibliographicItem.from_hash hash
=> #<RelatonOgc::OgcBibliographicItem:0x007fc322ef8548
...
----

=== Fetch data

This gem uses the https://raw.githubusercontent.com/opengeospatial/NamingAuthority/master/incubation/bibliography/bibliography.json dataset as a data source.

The method `RelatonOgc::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` (default `yaml`).

[source,ruby]
----
RelatonOgc::DataFetcher.fetch
Started at: 2021-09-14 11:21:46 +0200
[relaton-ogc] WARNING Duplicated documents: 15-113r5, 08-094r1, 10-025r1, 12-128r14, 16-079, 16-007r3, 13-026r8, 12-128r12, 15-078r6, 12-176r7, 09-102r3, 14-095, 14-115, 07-147r2, 12-000, 12-006, 09-025r1, 07-036, 07-110r4, 03-105r1, 06-042, 07-165r1, 12-066, 06-104r4, 11-122r1, 09-000, 04-094, 07-006r1, 06-035r1, 03-006r3, 05-134, 04-021r3, 02-058, 01-009
Stopped at: 2021-09-14 11:21:48 +0200
=> 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/calconnenct/relaton_ogc.

== License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).