Class: Barcodes::Exec
- Inherits:
-
Object
- Object
- Barcodes::Exec
- 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
-
#argv ⇒ Object
readonly
Array of command line arguments.
-
#options ⇒ Object
readonly
Hash of parsed options.
-
#parser ⇒ Object
readonly
The parser instance.
-
#symbology ⇒ Object
readonly
The barcode symbology.
-
#target ⇒ Object
readonly
The output target.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Exec
constructor
Creates a new instance with given command line arguments and options.
-
#run ⇒ Object
Runs the command and renders barcode.
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
#argv ⇒ Object (readonly)
Array of command line arguments
19 20 21 |
# File 'lib/barcodes/exec.rb', line 19 def argv @argv end |
#options ⇒ Object (readonly)
Hash of parsed options
25 26 27 |
# File 'lib/barcodes/exec.rb', line 25 def @options end |
#parser ⇒ Object (readonly)
The parser instance
22 23 24 |
# File 'lib/barcodes/exec.rb', line 22 def parser @parser end |
#symbology ⇒ Object (readonly)
The barcode symbology
28 29 30 |
# File 'lib/barcodes/exec.rb', line 28 def symbology @symbology end |
#target ⇒ Object (readonly)
The output target
31 32 33 |
# File 'lib/barcodes/exec.rb', line 31 def target @target end |
Instance Method Details
#run ⇒ Object
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.[:ascii] Barcodes::Renderer::Pdf.new(Barcodes.create(self.symbology, self.)).render(self.target) else Barcodes::Renderer::Ascii.new(Barcodes.create(self.symbology, self.)).render(self.target) end end rescue Exception => e puts e. end end |