Class: Labels::Exec

Inherits:
Object
  • Object
show all
Defined in:
lib/labels/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



35
36
37
38
39
40
# File 'lib/labels/exec.rb', line 35

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

Instance Attribute Details

#argvObject (readonly)

Array of command line arguments



20
21
22
# File 'lib/labels/exec.rb', line 20

def argv
  @argv
end

#optionsObject (readonly)

Hash of parsed options



26
27
28
# File 'lib/labels/exec.rb', line 26

def options
  @options
end

#parserObject (readonly)

The parser instance



23
24
25
# File 'lib/labels/exec.rb', line 23

def parser
  @parser
end

#sourceObject (readonly)

The input source



29
30
31
# File 'lib/labels/exec.rb', line 29

def source
  @source
end

#targetObject (readonly)

The output target



32
33
34
# File 'lib/labels/exec.rb', line 32

def target
  @target
end

Instance Method Details

#runObject

Runs the command and renders label



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/labels/exec.rb', line 43

def run
  begin
    document = Labels.open(self.source)
  
    unless document.nil?
      unless self.target.nil?
        document.render(self.target)
      else
        puts document.render
      end
    end
  rescue Exception => e
    puts e.message
  end
end