Class: LabelPrinter::PrintJob
- Inherits:
-
Object
- Object
- LabelPrinter::PrintJob
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/label_printer/print_job.rb
Instance Attribute Summary collapse
-
#label_class ⇒ Object
readonly
Returns the value of attribute label_class.
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#printer_name ⇒ Object
readonly
Returns the value of attribute printer_name.
Instance Method Summary collapse
- #build_attributes ⇒ Object
-
#execute ⇒ Object
rubocop:todo Metrics/MethodLength.
- #find_printer ⇒ Object
-
#initialize(printer_name, label_class, options) ⇒ PrintJob
constructor
A new instance of PrintJob.
-
#label_template_name ⇒ String
Returns the name of the label template to use for this print job.
-
#labels_attribute ⇒ Object
returns: a list of labels.
- #number_of_labels ⇒ Object
- #success ⇒ Object
Constructor Details
#initialize(printer_name, label_class, options) ⇒ PrintJob
Returns a new instance of PrintJob.
16 17 18 19 20 |
# File 'lib/label_printer/print_job.rb', line 16 def initialize(printer_name, label_class, ) @printer_name = printer_name @label_class = label_class @options = end |
Instance Attribute Details
#label_class ⇒ Object (readonly)
Returns the value of attribute label_class.
14 15 16 |
# File 'lib/label_printer/print_job.rb', line 14 def label_class @label_class end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
14 15 16 |
# File 'lib/label_printer/print_job.rb', line 14 def labels @labels end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/label_printer/print_job.rb', line 14 def @options end |
#printer_name ⇒ Object (readonly)
Returns the value of attribute printer_name.
14 15 16 |
# File 'lib/label_printer/print_job.rb', line 14 def printer_name @printer_name end |
Instance Method Details
#build_attributes ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/label_printer/print_job.rb', line 39 def build_attributes @build_attributes ||= { printer_name: printer_name, label_template_name: label_template_name, labels: labels_attribute } end |
#execute ⇒ Object
rubocop:todo Metrics/MethodLength
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/label_printer/print_job.rb', line 22 def execute # rubocop:todo Metrics/MethodLength begin LabelPrinter::PmbClient.print(build_attributes) rescue LabelPrinter::PmbException => e errors.add(:printmybarcode, e) return false rescue BarcodePrinter::BarcodePrinterException => e errors.add(:printer, e) return false rescue SampleManifest::MultiplexedLibraryBehaviour::Core::MxLibraryTubeException => e errors.add(:mx_tube, e) return false end true end |
#find_printer ⇒ Object
67 68 69 70 |
# File 'lib/label_printer/print_job.rb', line 67 def find_printer BarcodePrinter.find_by(name: printer_name) or raise BarcodePrinter::BarcodePrinterException.new, "Could not find barcode printer #{printer_name.inspect}" end |
#label_template_name ⇒ String
Returns the name of the label template to use for this print job. If not specified in the options during initialisation, the label template name configured for the printer in the database is used.
60 61 62 63 64 65 |
# File 'lib/label_printer/print_job.rb', line 60 def label_template_name return [:label_template_name] if [:label_template_name] printer = find_printer printer..label_template_name end |
#labels_attribute ⇒ Object
returns: a list of labels
48 49 50 51 52 |
# File 'lib/label_printer/print_job.rb', line 48 def labels_attribute printer = find_printer printer_type_class = { printer_type_class: printer..class } @labels = label_class.new(.merge(printer_type_class)).labels end |
#number_of_labels ⇒ Object
76 77 78 |
# File 'lib/label_printer/print_job.rb', line 76 def number_of_labels labels.count end |
#success ⇒ Object
72 73 74 |
# File 'lib/label_printer/print_job.rb', line 72 def success "Your #{number_of_labels} label(s) have been sent to printer #{printer_name}" end |