Class: Alexandria::Scanners::KeyboardWedge

Inherits:
Object
  • Object
show all
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

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
    data
  elsif data.length >= 13
    data[0, 13]
  else
    raise format(_("Unknown scan data %s<data>"), data: data)
  end
end

#display_nameObject



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

Returns:

  • (Boolean)


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

#nameObject



29
30
31
# File 'lib/alexandria/scanners/keyboard.rb', line 29

def name
  "KeyboardWedge"
end