Class: Isobib::IsoBibliography

Inherits:
Object
  • Object
show all
Defined in:
lib/isobib/iso_bibliography.rb

Overview

Class methods for search ISO standards.

Class Method Summary collapse

Class Method Details

.get(code, year, opts) ⇒ String

Returns Relaton XML serialisation of reference.

Parameters:

  • code (String)

    the ISO standard Code to look up (e..g “ISO 9000”)

  • year (String)

    the year the standard was published (optional)

  • opts (Hash)

    options; restricted to :all_parts if all-parts reference is required, :keep_year if undated reference should return actual reference with year

Returns:

  • (String)

    Relaton XML serialisation of reference



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/isobib/iso_bibliography.rb', line 34

def get(code, year, opts)
  if year.nil?
    /^(?<code1>[^:]+):(?<year1>[^:]+)$/ =~ code
    unless code1.nil?
      code = code1
      year = year1
    end
  end
  code += '-1' if opts[:all_parts]
  return Iecbib::IecBibliography.get(code, year, opts) if %r[^ISO/IEC DIR].match code
  ret = isobib_get1(code, year, opts)
  if ret.nil? && code =~ %r[^ISO\s]
    c = code.gsub "ISO", "ISO/IEC"
    warn "Attempting ISO/IEC retrieval"
    ret = isobib_get1(c, year, opts)
  end
  return nil if ret.nil?

  ret.to_most_recent_reference unless year || opts[:keep_year]
  ret.to_all_parts if opts[:all_parts]
  ret
end

.search(text) ⇒ Isobib::HitPages

Parameters:

  • text (String)

Returns:



14
15
16
17
18
19
20
21
# File 'lib/isobib/iso_bibliography.rb', line 14

def search(text)
  begin
    HitPages.new text
  rescue
    warn "Could not access http://www.iso.org"
    []
  end
end

.search_and_fetch(text) ⇒ Array<IsoBibliographicItem>

Parameters:

  • text (String)

Returns:

  • (Array<IsoBibliographicItem>)


25
26
27
# File 'lib/isobib/iso_bibliography.rb', line 25

def search_and_fetch(text)
  Scrapper.get(text)
end