Class: RelatonGb::GbBibliography
- Inherits:
-
Object
- Object
- RelatonGb::GbBibliography
- Defined in:
- lib/relaton_gb/gb_bibliography.rb
Overview
GB entry point class.
Class Method Summary collapse
-
.get(code, year = nil, opts = {}) ⇒ String
Relaton XML serialisation of reference.
-
.search(text) ⇒ RelatonGb::HitCollection
rubocop:disable Metrics/MethodLength.
Class Method Details
.get(code, year = nil, opts = {}) ⇒ String
Returns Relaton XML serialisation of reference.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/relaton_gb/gb_bibliography.rb', line 47 def get(code, year = nil, opts = {}) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity if year.nil? /^(?<code1>[^-]+)-(?<year1>[^-]+)$/ =~ code unless code1.nil? code = code1 year = year1 end end code += ".1" if opts[:all_parts] code, year = code.split("-", 2) if code.include?("-") ret = get1(code, year, opts) return nil if ret.nil? ret = ret.to_most_recent_reference unless year ret = ret.to_all_parts if opts[:all_parts] ret end |
.search(text) ⇒ RelatonGb::HitCollection
rubocop:disable Metrics/MethodLength
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/relaton_gb/gb_bibliography.rb', line 16 def search(text) case text when /^(GB|GJ|GS)/ # Scrape national standards. Util.info "Fetching from openstd.samr.gov.cn ...", key: text require "relaton_gb/gb_scrapper" GbScrapper.scrape_page text # when /^ZB/ # Scrape proffesional. # when /^DB/ # Scrape local standard. # when %r{^Q/} # Enterprise standard when %r{^T/[^\s]{2,6}\s} # Scrape social standard. Util.info "Fetching from www.ttbz.org.cn ...", key: text require "relaton_gb/t_scrapper" TScrapper.scrape_page text else # Scrape sector standard. # require "relaton_gb/sec_scrapper" # SecScrapper.scrape_page text [] end end |