Class: Alexandria::Scanners::CueCat
- Inherits:
-
Object
- Object
- Alexandria::Scanners::CueCat
- Includes:
- Logging
- Defined in:
- lib/alexandria/scanners/cue_cat.rb
Instance Method Summary collapse
-
#decode(data) ⇒ Object
Decodes CueCat input into ISBN The following code is adapted from Skip Rosebaugh's public domain perl implementation.
- #display_name ⇒ Object
-
#match?(data) ⇒ Boolean
Checks if data looks like cuecat input.
- #name ⇒ Object
Methods included from Logging
Instance Method Details
#decode(data) ⇒ Object
Decodes CueCat input into ISBN The following code is adapted from Skip Rosebaugh's public domain perl implementation.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/alexandria/scanners/cue_cat.rb', line 51 def decode(data) data = data.chomp fields = data.split(".") fields.shift # First part is gibberish fields.shift # Second part is cuecat serial number type, code = fields.map { |field| decode_field(field) } if type == "IB5" type = "IBN" code = code[0, 13] end begin if Library.valid_upc? code isbn13 = Library.canonicalise_ean(code) code = isbn13 type = "IBN" end rescue StandardError log.debug { "Cannot translate UPC (#{type}) code #{code} to ISBN" } end return code if type == "IBN" raise format(_("Don't know how to handle type %<type>s (barcode: %<code>s)"), type: type, code: code) end |
#display_name ⇒ Object
32 33 34 |
# File 'lib/alexandria/scanners/cue_cat.rb', line 32 def display_name "CueCat" end |
#match?(data) ⇒ Boolean
Checks if data looks like cuecat input
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/alexandria/scanners/cue_cat.rb', line 37 def match?(data) data = data.chomp return false if data[-1] != "." fields = data.split(".") return false if fields.size != 4 return false if fields[2].size != 4 true end |
#name ⇒ Object
28 29 30 |
# File 'lib/alexandria/scanners/cue_cat.rb', line 28 def name "CueCat" end |