Class: RelatonItu::ItuBibliography
- Inherits:
-
Object
- Object
- RelatonItu::ItuBibliography
- Defined in:
- lib/relaton_itu/itu_bibliography.rb
Overview
Class methods for search ISO standards.
Class Method Summary collapse
-
.get(code, year = nil, opts = {}) ⇒ String
Relaton XML serialisation of reference.
- .search(text, year = nil) ⇒ RelatonItu::HitCollection
Class Method Details
.get(code, year = nil, opts = {}) ⇒ String
Returns Relaton XML serialisation of reference.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/relaton_itu/itu_bibliography.rb', line 40 def get(code, year = nil, opts = {}) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity if year.nil? /^(?<code1>[^\s]+\s[^\s]+)\s\((\d{2}\/)?(?<year1>\d+)\)$/ =~ code unless code1.nil? code = code1 year = year1 end end code += "-1" if opts[:all_parts] ret = itubib_get1(code, year, opts) return nil if ret.nil? ret = ret.to_most_recent_reference unless year || opts[:keep_year] ret = ret.to_all_parts if opts[:all_parts] ret end |
.search(text, year = nil) ⇒ RelatonItu::HitCollection
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/relaton_itu/itu_bibliography.rb', line 21 def search(text, year = nil) # code = text.sub(/(?<=ITU-T\s\w)\.(\w+\.)(?=\d+)/, ' \1') if text =~ /(ITU-T\s\w)\.(Suppl\.|Annex)\s?(\w?\d+)/ correct_ref = "#{$~[1]} #{$~[2]} #{$~[3]}" warn "[relaton-itu] WARNING: Incorrect reference #{text}" warn "[relaton-itu] the reference should be #{correct_ref}" end HitCollection.new text, year rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, URI::InvalidURIError => e raise RelatonBib::RequestError, e. end |