Class: Barcodes::Exec

Inherits:
Object
  • Object
show all
Defined in:
lib/barcodes/exec.rb

Overview

This class is the main handler for the command line tool interface. It takes command line arguments and options and renders a barcode using those options.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Exec

Creates a new instance with given command line arguments and options



34
35
36
37
38
39
# File 'lib/barcodes/exec.rb', line 34

def initialize(argv)
  @argv = argv
  @options = {}
  self._init_parser
  self._parse!
end

Instance Attribute Details

#argvObject (readonly)

Array of command line arguments



19
20
21
# File 'lib/barcodes/exec.rb', line 19

def argv
  @argv
end

#optionsObject (readonly)

Hash of parsed options



25
26
27
# File 'lib/barcodes/exec.rb', line 25

def options
  @options
end

#parserObject (readonly)

The parser instance



22
23
24
# File 'lib/barcodes/exec.rb', line 22

def parser
  @parser
end

#symbologyObject (readonly)

The barcode symbology



28
29
30
# File 'lib/barcodes/exec.rb', line 28

def symbology
  @symbology
end

#targetObject (readonly)

The output target



31
32
33
# File 'lib/barcodes/exec.rb', line 31

def target
  @target
end

Instance Method Details

#runObject

Runs the command and renders barcode



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/barcodes/exec.rb', line 42

def run
  begin
    unless self.symbology.nil?
      unless self.options[:ascii]
        Barcodes::Renderer::Pdf.new(Barcodes.create(self.symbology, self.options)).render(self.target)
      else
        Barcodes::Renderer::Ascii.new(Barcodes.create(self.symbology, self.options)).render(self.target)
      end
    end
  rescue Exception => e
    puts e.message
  end
end