Class: Barby::ASCIIOutputter

Inherits:
Outputter show all
Defined in:
lib/barby/outputter/ascii_outputter.rb

Overview

Outputs an ASCII representation of the barcode. This is mostly useful for printing the barcode directly to the terminal for testing.

Registers to_ascii

Instance Attribute Summary

Attributes inherited from Outputter

#barcode

Instance Method Summary collapse

Methods inherited from Outputter

#initialize, register

Constructor Details

This class inherits a constructor from Barby::Outputter

Instance Method Details

#to_ascii(opts = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/barby/outputter/ascii_outputter.rb', line 14

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