= RelatonIec: retrieve IEC Standards for bibliographic use using the BibliographicItem model image:https://img.shields.io/gem/v/relaton-iec.svg["Gem Version", link="https://rubygems.org/gems/relaton-iec"] image:https://github.com/relaton/relaton-iec/workflows/macos/badge.svg["Build Status (macOS)", link="https://github.com/relaton/relaton-iec/actions?workflow=macos"] image:https://github.com/relaton/relaton-iec/workflows/windows/badge.svg["Build Status (Windows)", link="https://github.com/relaton/relaton-iec/actions?workflow=windows"] image:https://github.com/relaton/relaton-iec/workflows/ubuntu/badge.svg["Build Status (Ubuntu)", link="https://github.com/relaton/relaton-iec/actions?workflow=ubuntu"] image:https://codeclimate.com/github/relaton/relaton-iec/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/relaton/relaton-iec"] image:https://img.shields.io/github/issues-pr-raw/relaton/relaton-iec.svg["Pull Requests", link="https://github.com/relaton/relaton-iec/pulls"] image:https://img.shields.io/github/commits-since/relaton/relaton-iec/latest.svg["Commits since latest",link="https://github.com/relaton/relaton-iec/releases"] RelatonIec 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 IEC Standards from https://www.iec.ch, and access such metadata through the `IecBibliographicItem` object. == Installation Add this line to your application's Gemfile: [source,ruby] ---- gem 'relaton-iec' ---- And then execute: $ bundle Or install it yourself as: $ gem install relaton-iec == Usage === Search for a standard using keywords `RelatonIec::IecBibliography.search(ref, year)` method returns hits collection. Each hit can be used to fetch a document. - `ref` - a reference to search document - `year` - filter by year (optional) [source,ruby] ---- require 'relaton_iec' => true hit_collection = RelatonIec::IecBibliography.search("60050") => hit_collection.first => item = hit_collection[2].fetch => # [#, #] item.docidentifier.detect { |di| di.type == "URN" }.id => "urn:iec:std:iec:60050-07:1956-01:::" ---- === Fetch document by keywords `RelatonIec::IecBibliography.get(ref, year, opts)` method returns the document. - `ref` - a reference to search document - `year` - filter by year (optional) - `opts` - hash of options (optional). Supported options are `:all_parts` (boolean), `:keep_year` (boolean). [source,ruby] ---- item = RelatonIec::IecBibliography.get("IEC 60050-112:2010") [relaton-iec] ("IEC 60050-112:2010") fetching... [relaton-iec] ("IEC 60050-112:2010") found IEC 60050-112:2010 => # # # item = RelatonIec::IecBibliography.get("IEC 60050-112", "2010") [relaton-iec] ("IEC 60050-112") fetching... [relaton-iec] ("IEC 60050-112") found IEC 60050-112:2010 => # # ---- === Search for ISO/IEC Directives The following references are allowed to fetch: - `IEC 61360-4 DB` - IEC/SC 3D - Common Data Dictionary (CDD - V2.0015.0001) - `ISO/IEC DIR 1 IEC SUP` - Procedures for the technical work - Procedures specific to IEC - `ISO/IEC DIR 2 IEC` - Principles and rules for the structure and drafting of ISO and IEC documents - 'ISO/IEC DIR IEC SUP' - Procedures specific to IEC === XML serialization Possible options: - *bibdata* - If true then wrap item with _bibdata_ element and add _ext_ element. - *note* - Array of hashes `{ text: "Note", type: "note" }`. These notes will be added to XML. [source,ruby] ---- item.to_xml => " 2023-03-01 International Electrotechnical Vocabulary (IEV) - Part 112: Quantities and units Vocabulaire Electrotechnique International (IEV) - Partie 112: Grandeurs et unités Versión Oficial En español - Vocabulario Electrotécnico Internacional. Parte 112: Magnitudes y unidades. https://webstore.iec.ch/publication/162 ... " item.to_xml bibdata: true => " 2023-03-01 International Electrotechnical Vocabulary (IEV) - Part 112: Quantities and units Vocabulaire Electrotechnique International (IEV) - Partie 112: Grandeurs et unités Versión Oficial En español - Vocabulario Electrotécnico Internacional. Parte 112: Magnitudes y unidades. https://webstore.iec.ch/publication/162 https://webstore.iec.ch/preview/info_iec60050-112{ed1.0}b.pdf ... international-standard ... " item.to_xml note: [{ text: "Note", type: "note" }] => " ... Note ... " ---- === Typed links Each IEC document has `src` type link and optional `obp` type link. [source,ruby] ---- item.link => [#, @language=nil, @script=nil, @type="src">, #, @language=nil, @script=nil, @type="obp">] ---- === Create bibliographic item from Hash [source,ruby] ---- hash = YAML.load_file "spec/examples/hit.yaml" => {"schema-version"=>"v1.2.1", "id"=>"IEC61058-2-4-1995+AMD1-2003CSV", ... RelatonIec::IecBibliographicItem.from_hash hash => # "urn:iec:std:iec:60050-102:2007:::::amd:1:2017" RelatonIec.code_to_urn "IEC 60034-1:1969+AMD1:1977+AMD2:1979+AMD3:1980 CSV", "en-fr" => "urn:iec:std:iec:60034-1:1969::csv:en-fr:plus:amd:1:1977:plus:amd:2:1979:plus:amd:3:1980" ---- The method `RelatonIec.urn_to_code(urn)` converts URN to document identifier. [source,ruby] ---- RelatonIec.urn_to_code "urn:iec:std:iec:60050-102:2007:::::amd:1:2017" => ["IEC 60050-102:2007/AMD1:2017", ""] RelatonIec.urn_to_code "urn:iec:std:iec:60034-1:1969::csv:en-fr:plus:amd:1:1977:plus:amd:2:1979:plus:amd:3:1980" => ["IEC 60034-1:1969+AMD1:1977+AMD2:1979+AMD3:1980 CSV", "en-fr"] ---- === Fetch data This gem uses the https://bitbucket.org/sdo-hapi/api-specifications/wiki/Guidelines[Harmonized API] as a data source. The following options are available: - `iec-harmonized-all` - fetches all the documents using the API - `iec-harmonized-latest` - fetches the latest documents using the API The method `RelatonIec::DataFetcher.new(source, output: "data", format: "yaml").fetch` fetches IEC documents from the dataset and saves them to the `./data` folder in YAML format. Arguments: - `source` - data source. Possible values: `iec-harmonized-all`, `iec-harmonized-latest` (default `iec-harmonized-latest`). - `output` - folder to save documents (default './data'). - `format` - the format in which the documents are saved. Possible formats are: `yaml`, `xml`, `bibxxml` (default `yaml`). [source,ruby] ---- RelatonIec::DataFetcher.new.fetch Started at: 2022-06-23 09:36:55 +0200 Stopped at: 2022-06-23 09:36:58 +0200 Done in: 752 sec. => 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). == Exceptional Citations This gem retrieves bibliographic descriptions of ISO documents by doing searches on the ISO website, http://www.iso.org, and screenscraping the document that matches the queried document identifier. The following documents are not returned as search results from the ISO website, and the gem returns manually generated references to them. * `IEV`: used in the metanorma-iso gem to reference Electropedia entries generically. Is resolved to an "all parts" reference to IEC 60050, which in turn is resolved into the specific documents cited by their top-level clause. == Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/metanorma/relaton-iec. == License The gem is available as open source under the terms of the https://opensource.org/licenses/MIT[MIT License].