Sha256: 94e5a764ac651b5907b7a9fd329e21c3589203bdd031bec82f4fd915668a61f2
Contents?: true
Size: 1.75 KB
Versions: 5
Compression:
Stored size: 1.75 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 format(_("Unknown scan data %s<data>"), data: data) end end end # Register the wedge scanner with the Scanner Registry register KeyboardWedge.new end end
Version data entries
5 entries across 5 versions & 1 rubygems