Gem Version Build Status (macOS) Build Status (Windows) Build Status (Ubuntu) Code Climate Pull Requests Commits since latest

RelatonGb is a Ruby gem that searches and fetches Chinese GB standards. The standards scraped form:

Note
Unlike the ISO website, the GB websites require the year of publication to be included in the search. So a standard will not be found successfully through this gem unless the year is included in its document identifier: for example, not CN(GB/T 1.1), but CN(GB/T 1.1-2009).

Installation

Add this line to your application’s Gemfile:

gem 'relaton-gb'

And then execute:

$ bundle

Or install it yourself as:

$ gem install relaton-gb

Usage

Search document

require 'relaton_gb'
=> true

hit_collection = RelatonGb::GbBibliography.search "GB/T 20223-2006"
[relaton-gb] (GB/T 20223-2006) Fetching from openstd.samr.gov.cn ...
=> <RelatonGb::HitCollection:0x007fc8d8a26d10 @ref= @fetched=false>

hit_collection.first
=> <RelatonGb::Hit:0x007fc8d8a27c88 @fullIdentifier="" @docref="GB/T 20223-2006">

Scrape document form collection

hit_collection.first.fetch
=> <RelatonGb::GbBibliographicItem:0x007f975a0219c8>

hit_collection.first.fetch.committee
=> #<RelatonGb::GbTechnicalCommittee:0x007f975713c450 @name="中国纤维检验局", @type="technical">

hit_collection.first.fetch.gbtype
=> #<RelatonGb::GbStandardType:0x0000000112957dc0 @mandate="recommended", @prefix="GB_national", @scope="national", @topic="other">

hit_collection.first.fetch.ccs
=> [#<Cnccs::Ccs:0x007f975713c090
  @code="B32",
  @description="纤维作物与产品",
  @description_full="农业、林业; 经济作物; 纤维作物与产品",
  @fieldcode="B",
  @groupcode="30/39",
  @notes=[#<Cnccs::Note:0x007f975716edb0 @ccs_code="", @text="棉、麻等">],
  @subgroupcode="32">]

hit_collection.first.fetch.title
=> #<RelatonBib::TypedTitleStringCollection:0x0000000112a1ac08
 @array=
  [#<RelatonBib::TypedTitleString:0x0000000112a1f438
    @title=#<RelatonBib::FormattedString:0x0000000112cd6050 @content="棉短绒", @format="text/plain", @language=["zh"], @script=["Hans"]>,
    @type="title-main">,
   #<RelatonBib::TypedTitleString:0x0000000112a1eb78
    @title=#<RelatonBib::FormattedString:0x0000000112cd6000 @content="棉短绒", @format="text/plain", @language=["zh"], @script=["Hans"]>,
    @type="main">,
   #<RelatonBib::TypedTitleString:0x0000000112a1c198
    @title=#<RelatonBib::FormattedString:0x0000000112cd5ce0 @content="Cotton linter", @format="text/plain", @language=["en"], @script=["Latn"]>,
    @type="title-main">,
   #<RelatonBib::TypedTitleString:0x0000000112a1bba8
    @title=#<RelatonBib::FormattedString:0x0000000112cd5c40 @content="Cotton linter", @format="text/plain", @language=["en"], @script=["Latn"]>,
    @type="main">]>

hit_collection.first.fetch.date
=> [#<RelatonBib::BibliographicDate:0x000000011307f468 @from=nil, @on="2006-03-10", @to=nil, @type="published">]

Get document by identifier

RelatonGb::GbBibliography.get "GB/T 20223-2006"
[relaton-gb] (GB/T 20223-2006) Fetching from openstd.samr.gov.cn ...
[relaton-gb] (GB/T 20223-2006) Found: `GB/T 20223-2006`
=> <RelatonGb::GbBibliographicItem:0x000000000011f8>

Get document by identifier and year

RelatonGb::GbBibliography.get "GB/T 20223", "2006"
[relaton-gb] (GB/T 20223-2006) Fetching from openstd.samr.gov.cn ...
[relaton-gb] (GB/T 20223-2006) Found: `GB/T 20223-2006`
=> <RelatonGb::GbBibliographicItem:0x00000000001248>

Create bibliographic item from YAML

hash = YAML.load_file 'spec/examples/gb_bib_item.yml'
=> {"id"=>"JB/T13368",
...

RelatonGb::GbBibliographicItem.from_hash hash
=> <RelatonGb::GbBibliographicItem:0x007fc680802700>

Serialization

hit_collection.first.fetch.to_xml
=> "<bibitem id="GB/T20223-2006" type="standard" schema-version="v1.2.1">
      <fetched>2022-12-03</fetched>
      <title type="title-main" format="text/plain" language="zh" script="Hans">棉短绒</title>
      <title type="main" format="text/plain" language="zh" script="Hans">棉短绒</title>
      <title type="title-main" format="text/plain" language="en" script="Latn">Cotton linter</title>
      ...
    </bibitem>"

With bibdata: true option XML output is wrapped with bibdata element and ext element added.

hit_collection.first.fetch.to_xml bibdata: true
=> "<bibdata type="standard" schema-version="v1.2.1">
      <fetched>2022-12-03</fetched>
      <title type="title-main" format="text/plain" language="zh" script="Hans">棉短绒</title>
      <title type="main" format="text/plain" language="zh" script="Hans">棉短绒</title>
      <title type="title-main" format="text/plain" language="en" script="Latn">Cotton linter</title>
      <title type="main" format="text/plain" language="en" script="Latn">Cotton linter</title>
      ...
      <ext schema-version="v1.0.0">
        <doctype>standard</doctype>
        ...
      </ext>
    </bibdata>"

Each GB document has src type link.

hit_collection.first.fetch.link
=> [#<RelatonBib::TypedUri:0x00007fee2c0257e8 @content=#<Addressable::URI:0x67c URI:http://openstd.samr.gov.cn/bzgk/gb/newGbInfo?hcno=083B48FA72DBD3B9BDE74507BC31736A>, @type="src">]

Logging

RelatonGb uses the relaton-logger gem for logging. By default, it logs to STDOUT. To change the log levels and add other loggers, read the 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](https://rubygems.org).

Contributing

Bug reports and pull requests are welcome on GitHub at USERNAME/gdbib.

License

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