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

RelatonGb is a Ruby gem that search and fetch 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'

hit_collection = RelatonGb::GbBibliography.search "GB/T 20223-2006"
=> <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:0x007f9758087018 @mandate="recommended", @prefix="GB_national", @scope="national">

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
=> [#<RelatonIsoBib::TypedTitleString:0x007f975714cfa8
  @title=#<RelatonBib::FormattedString:0x007f975714cb20 @content="棉短绒", @format="text/plain", @language=["zh"], @script=["Hans"]>,
  @type="title-main">,
 #<RelatonIsoBib::TypedTitleString:0x007f975714c580
  @title=#<RelatonBib::FormattedString:0x007f9757147f08 @content="棉短绒", @format="text/plain", @language=["zh"], @script=["Hans"]>,
  @type="main">,
 #<RelatonIsoBib::TypedTitleString:0x007f97571477d8
  @title=#<RelatonBib::FormattedString:0x007f9757146ec8 @content="Cotton linter", @format="text/plain", @language=["en"], @script=["Latn"]>,
  @type="title-main">,
 #<RelatonIsoBib::TypedTitleString:0x007f97571465e0
  @title=#<RelatonBib::FormattedString:0x007f9757146158 @content="Cotton linter", @format="text/plain", @language=["en"], @script=["Latn"]>,
  @type="main">]

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

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\">
  <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>
  <uri type="src">http://www.std.gov.cn/gb/search/gbDetailed?id=71F772D778ADD3A7E05397BE0A0AB82A</uri>
  <docidentifier type="Chinese Standard">GB/T 20223-2006</docidentifier>
  <date type="published">
    <on>2006</on>
  </date>
  <contributor>
    <role type="publisher"/>
    <organization>
      <name language="en">General Administration of Quality Supervision, Inspection and Quarantine; Standardization Administration of China</name>
      <name language="zh">中华人民共和国国家质量监督检验检疫总局 中国国家标准化管理委员会</name>
    </organization>
  </contributor>
  <language>zh</language>
  <script>Hans</script>
  <status>
    <stage>obsoleted</stage>
  </status>
</bibitem>"

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

hit_collection.first.fetch.to_xml bibdata: true
=>"<bibdata type="international-standard">
  <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>
  <uri type="src">http://www.std.gov.cn/gb/search/gbDetailed?id=71F772D778ADD3A7E05397BE0A0AB82A</uri>
  <docidentifier type="Chinese Standard">GB/T 20223-2006</docidentifier>
  <date type="published">
    <on>2006</on>
  </date>
  <contributor>
    <role type="publisher"/>
    <organization>
      <name language="en">General Administration of Quality Supervision, Inspection and Quarantine; Standardization Administration of China</name>
      <name language="zh">中华人民共和国国家质量监督检验检疫总局 中国国家标准化管理委员会</name>
    </organization>
  </contributor>
  <language>zh</language>
  <script>Hans</script>
  <status>
    <stage>obsoleted</stage>
  </status>
  <ext>
    <doctype>international-standard</doctype>
    <gbcommittee type="technical">中国纤维检验局</gbcommittee>
    <ics>
      <code>59.060.10</code>
      <text>Natural fibres</text>
    </ics>
    <structuredidentifier type="Chinese Standard">
      <project-number>GB/T 20223</project-number>
    </structuredidentifier>
    <gbtype>
      <gbscope>national</gbscope>
      <gbprefix>GB_national</gbprefix>
      <gbmandate>recommended</gbmandate>
    </gbtype>
    <ccs>
      <code>B32</code>
      <text>纤维作物与产品</text>
    </ccs>
    <gbplannumber>GB/T 20223</gbplannumber>
  </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">]

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).