Class: Barby::DataMatrix

Inherits:
Barcode2D show all
Defined in:
lib/barby/barcode/data_matrix.rb

Overview

Uses the semacode library (gem install semacode) to encode DataMatrix barcodes

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Barcode

#method_missing, #outputter_class_for, #outputter_for, outputters, register_outputter, #two_dimensional?, #valid?

Constructor Details

#initialize(data) ⇒ DataMatrix

Returns a new instance of DataMatrix.



13
14
15
# File 'lib/barby/barcode/data_matrix.rb', line 13

def initialize(data)
  self.data = data
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Barby::Barcode

Instance Attribute Details

#dataObject

Returns the value of attribute data.



10
11
12
# File 'lib/barby/barcode/data_matrix.rb', line 10

def data
  @data
end

Instance Method Details

#encoderObject



23
24
25
# File 'lib/barby/barcode/data_matrix.rb', line 23

def encoder
  @encoder ||= ::DataMatrix::Encoder.new(data)
end

#encodingObject



28
29
30
# File 'lib/barby/barcode/data_matrix.rb', line 28

def encoding
  encoder.data.map{|a| a.map{|b| b ? '1' : '0' }.join }
end

#semacode?Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/barby/barcode/data_matrix.rb', line 33

def semacode?
  #TODO: Not sure if this is right
  data =~ /^http:\/\//
end

#to_sObject



39
40
41
# File 'lib/barby/barcode/data_matrix.rb', line 39

def to_s
  data
end