Sha256: e341383cff73b44e867857f9f112e7a2e54c98a18f6e6ad05f54305c257e940a
Contents?: true
Size: 911 Bytes
Versions: 11
Compression:
Stored size: 911 Bytes
Contents
require 'barby/outputter' module Barby #Outputs an ASCII representation of the barcode. This is mostly useful for printing #the barcode directly to the terminal for testing. # #Registers to_ascii class ASCIIOutputter < Outputter register :to_ascii def to_ascii(opts={}) default_opts = {:height => 10, :xdim => 1, :bar => '#', :space => ' '} default_opts.update(:height => 1, :bar => ' X ', :space => ' ') if barcode.two_dimensional? opts = default_opts.merge(opts) if barcode.two_dimensional? booleans.map do |bools| line_to_ascii(bools, opts) end.join("\n") else line_to_ascii(booleans, opts) end end private def line_to_ascii(booleans, opts) Array.new( opts[:height], booleans.map{|b| (b ? opts[:bar] : opts[:space]) * opts[:xdim] }.join ).join("\n") end end end
Version data entries
11 entries across 11 versions & 3 rubygems