= RelatonBib
image:https://img.shields.io/gem/v/relaton-bib.svg["Gem Version", link="https://rubygems.org/gems/relaton-bib"]
image:https://github.com/relaton/relaton-bib/workflows/rake/badge.svg["Build Status", link="https://github.com/relaton/relaton-bib/actions?workflow=rake"]
image:https://codeclimate.com/github/relaton/relaton-bib/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/relaton/relaton-bib"]
image:https://img.shields.io/github/issues-pr-raw/relaton/relaton-bib.svg["Pull Requests", link="https://github.com/relaton/relaton-bib/pulls"]
image:https://img.shields.io/github/commits-since/relaton/relaton-bib/latest.svg["Commits since latest",link="https://github.com/relaton/relaton-bib/releases"]
RlatonBib is a Ruby gem that implements the https://github.com/metanorma/relaton-models#bibliography-uml-models[BibliographicItem model].
== Installation
Add this line to your application's Gemfile:
[source,ruby]
----
gem 'relaton-bib'
----
And then execute:
$ bundle
Or install it yourself as:
$ gem install relaton-bib
== Usage
=== Create bibliographic item
[source,ruby]
----
require 'relaton_bib'
=> true
hash = YAML.load_file "spec/examples/bib_item.yml"
=> {"id"=>"ISOTC211",
"fetched"=>"2022-05-02",
"title"=>["Geographic information", {"content"=>"Information géographique", "language"=>"fr", "script"=>"Latn"}],
...
item = RelatonBib::BibliographicItem.from_hash(hash)
=> # #,
@type="title-main">,
#,
@type="main">,
#,
@type=nil>]>
item.title lang: "fr"
=> #,
@type=nil>]>
----
=== BibliographicItem Formatted Strings
[source,ruby]
----
item.abstract
=> [#ISO 19115-1:2014 defines the schema required for ...
",
@format="text/html",
@language=["en"],
@script=["Latn"]>,
#]
item.abstract(lang: "en").to_s
=> "ISO 19115-1:2014 defines the schema required for ...
"
----
=== BibliographicItem references
[source,ruby]
----
item.shortref item.docidentifier.first
=> "ISOTC211:2014"
----
=== XML serialization
[source,ruby]
----
item.to_xml
=> "
2022-05-02
Geographic information
Geographic information
Information géographique
...
"
----
The default root element is `bibitem`. With argument `bibdata: true` the XML wrapped with `bibdata` element.
[source,ruby]
----
item.to_xml bibdata: true
=> "
2022-05-02
Geographic information
...
document
subdocument
...
"
----
==== Date format
By default date elements are formatted as a year (yyyy). Option `:date_format` allows to output date elements in `:short` (yyyy-mm) and `:full` (yyyy-mm-dd) additional formats.
[source,ruby]
----
item.to_xml date_format: :short
=> "
2022-05-02
Geographic information
...
2014-01
2014-04
2015-05
...
"
item.to_xml date_format: :full
=> "
...
2014-01-01
2014-04-01
2015-05-20
...
"
----
==== Adding notes
[source,ruby]
----
item.to_xml note: [{ text: "Note", type: "note" }]
=> "
...
Note
...
"
----
=== Create bibliographic item form YAML
[source,ruby]
----
hash = YAML.load_file 'spec/examples/bib_item.yml'
=> {"id"=>"ISOTC211"
...
RelatonBib::BibliographicItem.from_hash hash
=> # # {"schema-version"=>"v1.2.1",
"id"=>"ISOTC211",
"title"=>
[{"content"=>"Geographic information", "format"=>"text/plain", "type"=>"title-main"},
{"content"=>"Geographic information", "format"=>"text/plain", "type"=>"main"},
{"content"=>"Information géographique", "language"=>["fr"], "script"=>["Latn"], "format"=>"text/plain"}],
...
----
=== Create bibliographic item from BibTeX
[source,ruby]
----
RelatonBib::BibtexParser.from_bibtex File.read('spec/examples/techreport.bib')
=> {"ISOTC211"=>
# @misc{ISOTC211,
title = {Geographic information},
edition = {Edition 1},
author = {Bierman, A. and Bierman, Arnold and Bierman, Arnold B},
...
----
=== Export bibliographic item to Citeproc
[source,ruby]
----
item.to_citeproc
=> [{"title"=>"Geographic information",
"edition"=>"Edition 1",
"author"=>[{"family"=>"Bierman", "given"=>"A."}, {"family"=>"Bierman", "given"=>"Arnold"}, {"family"=>"Bierman", "given"=>"Arnold B"}],
"publisher"=>"Institute of Electrical and Electronics Engineers",
"publisher-place"=>"bib place",
...
----
=== Exporting bibliographic item to AsciiBib
[source,ruby]
----
item.to_asciibib
=> [%bibitem]
== {blank}
id:: ISOTC211
fetched:: 2022-05-02
title::
title.type:: title-main
title.content:: Geographic information
title.format:: text/plain
...
----
=== Export bibliographic item to BibXML (RFC)
[source,ruby]
----
item.to_bibxml
=> "
Geographic information
International Organization for Standardization
..
...
"
----
== 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/metanorma/relaton-bib.
== License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).