Print

Print


Based on https://www.oclc.org/batchload/controlnumber.en.html, this ruby function should get the job done:

def oclc_normalize oclc
  oclc_num = oclc.gsub(/\D/, '').to_i.to_s
  case oclc_num.length
  when 1..8
    "ocm" + "%08d" % oclc_num
  when 9
    "ocn" + oclc_num
  else
    "on" + oclc_num
  end
end

examples:
oclc_normalize("(OCoLC)3851870") => ocm03851870
oclc_normalize("123456789") => ocn123456789
oclc_normalize("(OCoLC)1987654041") => on1987654041
oclc_normalize("42") => ocm00000042


I'm actually currently working on stripping out all of the prefixes from the OCLC number to index into Solr. I wanted the number without any leading zeros, and that gets handled by the first line of the function.