Class: Alexandria::Scanners::KeyboardWedge
- Inherits:
-
Object
- Object
- Alexandria::Scanners::KeyboardWedge
- Defined in:
- lib/alexandria/scanners/keyboard.rb
Overview
A simple keyboard-wedge style barcode scanner which presents scan data as if typed from a keyboard. (Modified CueCats act like this.)
Instance Method Summary collapse
-
#decode(data) ⇒ Object
Gets the essential 13-digits from an ISBN barcode (EAN-13).
- #display_name ⇒ Object
-
#match?(data) ⇒ Boolean
Checks if data looks like a completed scan.
- #name ⇒ Object
Instance Method Details
#decode(data) ⇒ Object
Gets the essential 13-digits from an ISBN barcode (EAN-13)
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/alexandria/scanners/keyboard.rb', line 44 def decode(data) data.gsub!(/\s/, '') if data.length == 10 return data elsif data.length >= 13 return data[0, 13] else raise "Unknown scan data #{data}" end end |
#display_name ⇒ Object
33 34 35 |
# File 'lib/alexandria/scanners/keyboard.rb', line 33 def display_name 'Keyboard Wedge' end |
#match?(data) ⇒ Boolean
Checks if data looks like a completed scan
38 39 40 41 |
# File 'lib/alexandria/scanners/keyboard.rb', line 38 def match?(data) data.gsub!(/\s/, '') (data =~ /[0-9]{12,18}/) || (data =~ /[0-9]{9}[0-9Xx]/) end |
#name ⇒ Object
29 30 31 |
# File 'lib/alexandria/scanners/keyboard.rb', line 29 def name 'KeyboardWedge' end |