Sha256: 43970bd0aea7d21bfe41cfb4f7c17c325e9d4d3e0ffad97482c7dde2e5753151
Contents?: true
Size: 1.73 KB
Versions: 1
Compression:
Stored size: 1.73 KB
Contents
# frozen_string_literal: true # Copyright (C) 2005-2006 Christopher Cyll # Copyright (C) 2008 Cathal Mc Ginley # # Alexandria is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # # Alexandria is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public # License along with Alexandria; see the file COPYING. If not, # write to the Free Software Foundation, Inc., 51 Franklin Street, # Fifth Floor, Boston, MA 02110-1301 USA. require "alexandria/scanners" module Alexandria module Scanners # A simple keyboard-wedge style barcode scanner which presents # scan data as if typed from a keyboard. (Modified CueCats act # like this.) class KeyboardWedge def name "KeyboardWedge" end def display_name "Keyboard Wedge" end # Checks if data looks like a completed scan def match?(data) data.gsub!(/\s/, "") (data =~ /[0-9]{12,18}/) || (data =~ /[0-9]{9}[0-9Xx]/) end # Gets the essential 13-digits from an ISBN barcode (EAN-13) def decode(data) data.gsub!(/\s/, "") if data.length == 10 data elsif data.length >= 13 data[0, 13] else raise "Unknown scan data #{data}" end end end # Register the wedge scanner with the Scanner Registry register KeyboardWedge.new end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
alexandria-book-collection-manager-0.7.5 | lib/alexandria/scanners/keyboard.rb |