lib/relaton_iso/iso_bibliography.rb in relaton-iso-0.8.0 vs lib/relaton_iso/iso_bibliography.rb in relaton-iso-0.8.1

- old
+ new

@@ -17,28 +17,23 @@ Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, OpenSSL::SSL::SSLError, Errno::ETIMEDOUT raise RelatonBib::RequestError, "Could not access http://www.iso.org" end - # @param text [String] - # @return [Array<RelatonIso::IsoBibliographicItem>] - # def search_and_fetch(text) - # Scrapper.get(text) - # end - # @param ref [String] the ISO standard Code to look up (e..g "ISO 9000") - # @param year [String] the year the standard was published (optional) - # @param opts [Hash] options; restricted to :all_parts if all-parts reference is required, - # :keep_year if undated reference should return actual reference with year + # @param year [String, NilClass] the year the standard was published + # @param opts [Hash] options; restricted to :all_parts if all-parts + # reference is required, :keep_year if undated reference should + # return actual reference with year # @return [String] Relaton XML serialisation of reference - def get(ref, year, opts) + def get(ref, year = nil, opts = {}) opts[:ref] = ref %r{ ^(?<code1>[^\s]+\s[^/]+) # match code /? - (?<corr>(Amd|DAmd|(CD|WD|AWI|NP)\sAmd|Cor|CD\sCor|FDAmd)\s\d+ # correction name + (?<corr>(Amd|DAmd|(CD|WD|AWI|NP)\sAmd|Cor|CD\sCor|FDAmd|PRF\sAmd)\s\d+ # correction name :?(\d{4})?(/Cor\s\d+:\d{4})?) # match correction year }x =~ ref code = code1 || ref if year.nil? @@ -120,11 +115,11 @@ # @param result [RelatonIso::HitCollection] # @param corr [String] correction # @param opts [Hash] def try_stages(result, corr, opts) res = nil - %w[NP WD CD DIS FDIS PRF IS AWI].each do |st| # try stages + %w[NP WD CD DIS FDIS PRF IS AWI TR].each do |st| # try stages c = yield st res = search_code result, c, corr, opts return res unless res.empty? end res @@ -132,12 +127,12 @@ def search_code(result, code, corr, opts) result.select do |i| (opts[:all_parts] || i.hit["docRef"] =~ %r{^#{code}(?!-)}) && ( corr && %r{^#{code}[\w-]*(:\d{4})?/#{corr}} =~ i.hit["docRef"] || - %r{^#{code}[\w-]*(:\d{4})?/} !~ i.hit["docRef"] && !corr - ) + !corr && %r{^#{code}[\w-]*(:\d{4})?/} !~ i.hit["docRef"] + ) # && %r{^#{code}} =~ i.hit["docRef"] end end # Sort through the results from RelatonIso, fetching them three at a time, # and return the first result that matches the code, @@ -157,14 +152,18 @@ hts end end return { years: missed_years } unless hits.any? - return { ret: hits.first.fetch } if !opts[:all_parts] || hits.size == 1 + return { ret: hits.first.fetch(opts[:lang]) } if !opts[:all_parts] || hits.size == 1 - { ret: hits.to_all_parts } + { ret: hits.to_all_parts(opts[:lang]) } end + # @param code [String] + # @param year [String, NilClass] + # @param corr [String, NilClass] + # @param opts [Hash] def isobib_get1(code, year, corr, opts) # return iev(code) if /^IEC 60050-/.match code result = isobib_search_filter(code, corr, opts) || return ret = isobib_results_filter(result, year, opts) if ret[:ret]