Sha256: e735627b9e461ebd879c571f14f8a12eb83f1d03b60cb03f360baa8bf83447dd

Contents?: true

Size: 1.71 KB

Versions: 4

Compression:

Stored size: 1.71 KB

Contents

# 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
          return data
        elsif data.length >= 13
          return 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

4 entries across 4 versions & 1 rubygems

Version Path
alexandria-book-collection-manager-0.7.1 lib/alexandria/scanners/keyboard.rb
alexandria-book-collection-manager-0.7.0 lib/alexandria/scanners/keyboard.rb
alexandria-book-collection-manager-0.6.9 lib/alexandria/scanners/keyboard.rb
alexandria-book-collection-manager-0.6.9.pre1 lib/alexandria/scanners/keyboard.rb