Module: Barcodes

Defined in:
lib/barcodes.rb,
lib/barcodes/exec.rb,
lib/barcodes/version.rb,
lib/barcodes/symbology.rb,
lib/barcodes/renderer/pdf.rb,
lib/barcodes/symbology/ean.rb,
lib/barcodes/symbology/msi.rb,
lib/barcodes/renderer/ascii.rb,
lib/barcodes/renderer/image.rb,
lib/barcodes/symbology/base.rb,
lib/barcodes/symbology/ean8.rb,
lib/barcodes/symbology/upca.rb,
lib/barcodes/symbology/ean13.rb,
lib/barcodes/symbology/code11.rb,
lib/barcodes/symbology/code39.rb,
lib/barcodes/symbology/code93.rb,
lib/barcodes/symbology/planet.rb,
lib/barcodes/symbology/codabar.rb,
lib/barcodes/symbology/code128.rb,
lib/barcodes/symbology/postnet.rb,
lib/barcodes/symbology/msimod10.rb,
lib/barcodes/symbology/msimod11.rb,
lib/barcodes/symbology/code39mod43.rb,
lib/barcodes/symbology/standard2of5.rb,
lib/barcodes/symbology/code39extended.rb,
lib/barcodes/symbology/code93extended.rb,
lib/barcodes/symbology/interleaved2of5.rb,
lib/barcodes/symbology/standard2of5mod10.rb,
lib/barcodes/symbology/code39extendedmod43.rb,
lib/barcodes/symbology/interleaved2of5mod10.rb

Overview

Barcodes is a RubyGem for creating and rendering common barcode symbologies. Here are some of the current features:

  • Many common symbologies to choose from

  • PDF and ASCII rendering support

  • Command line interface for rendering barcodes to console or file

Currently supported symbologies:

  • Code 11

  • Code 128

  • Code 39

  • Code 39 Mod 43

  • Code 39 Extended

  • Code 39 Extended Mod 43

  • Code 93

  • Code 93 Extended

  • EAN8

  • EAN13

  • Interleaved 2 of 5

  • Interleaved 2 of 5 Mod 10

  • MSI

  • MSI Mod 10

  • MSI Mod 11

  • PLANET

  • POSTNET

  • Standard 2 of 5

  • Standard 2 of 5 Mod 10

  • UPC-A

Defined Under Namespace

Modules: Renderer, Symbology Classes: Exec

Constant Summary collapse

VERSION =

Returns the current version

"0.0.12"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(symbology, options = {}) ⇒ Object

Creates a new barcode of type <symbology> with given options and returns an instantiated instance.

See Barcodes::Symbology::Base for options



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/barcodes.rb', line 51

def create(symbology, options={})
  if Symbology::CODABAR.include? symbology
    return Symbology::Codabar.new(options)
  elsif Symbology::CODE_11.include? symbology
    return Symbology::Code11.new(options)
  elsif Symbology::CODE_39.include? symbology
    return Symbology::Code39.new(options)
  elsif Symbology::CODE_39_MOD_43.include? symbology
    return Symbology::Code39Mod43.new(options)
  elsif Symbology::CODE_39_EXTENDED.include? symbology
    return Symbology::Code39Extended.new(options)
  elsif Symbology::CODE_39_EXTENDED_MOD_43.include? symbology
    return Symbology::Code39ExtendedMod43.new(options)
  elsif Symbology::CODE_93.include? symbology
    return Symbology::Code93.new(options)
  elsif Symbology::CODE_93_EXTENDED.include? symbology
    return Symbology::Code93Extended.new(options)
  elsif Symbology::CODE_128.include? symbology
    return Symbology::Code128.new(options)
  elsif Symbology::EAN_8.include? symbology
    return Symbology::Ean8.new(options)
  elsif Symbology::EAN_13.include? symbology
    return Symbology::Ean13.new(options)
  elsif Symbology::MSI.include? symbology
    return Symbology::Msi.new(options)
  elsif Symbology::MSI_MOD_10.include? symbology
    return Symbology::MsiMod10.new(options)
  elsif Symbology::MSI_MOD_11.include? symbology
    return Symbology::MsiMod11.new(options)
  elsif Symbology::STANDARD_2_OF_5.include? symbology
    return Symbology::Standard2Of5.new(options)
  elsif Symbology::STANDARD_2_OF_5_MOD_10.include? symbology
    return Symbology::Standard2Of5Mod10.new(options)
  elsif Symbology::INTERLEAVED_2_OF_5.include? symbology
    return Symbology::Interleaved2Of5.new(options)
  elsif Symbology::INTERLEAVED_2_OF_5_MOD_10.include? symbology
    return Symbology::Interleaved2Of5Mod10.new(options)
  elsif Symbology::PLANET.include? symbology
    return Symbology::Planet.new(options)
  elsif Symbology::POSTNET.include? symbology
    return Symbology::Postnet.new(options)
  elsif Symbology::UPC_A.include? symbology
    return Symbology::UpcA.new(options)
  else
    raise ArgumentError, 'Unsupported symbology'
  end
  
  # Creates a new barcode of type <symbology> with given
  # options and renders barcode.
  #
  # Optionally takes <filename>. If no
  # filename is given rendering will be outputted as a
  # string.
  #
  # Uses PDF renderer by default.
  # 
  # See Barcodes::Symbology::Base for options
  def render(symbology, filename=nil, options={})
    Barcodes::Renderer::Pdf.new(self.create(symbology, options)).render(filename)
  end
end

Instance Method Details

#render(symbology, filename = nil, options = {}) ⇒ Object

Creates a new barcode of type <symbology> with given options and renders barcode.

Optionally takes <filename>. If no filename is given rendering will be outputted as a string.

Uses PDF renderer by default.

See Barcodes::Symbology::Base for options



108
109
110
# File 'lib/barcodes.rb', line 108

def render(symbology, filename=nil, options={})
  Barcodes::Renderer::Pdf.new(self.create(symbology, options)).render(filename)
end