Class: Barby::DataMatrix
- Defined in:
- lib/barby/barcode/data_matrix.rb
Overview
Uses the dmtx library (gem install dmtx) to encode DataMatrix barcodes
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
-
#bit?(x, y) ⇒ Boolean
NOTE: this method is not exposed via the gem so using send ahead of opening a PR to hopefully support:.
- #encoder ⇒ Object
-
#encoding ⇒ String
Converts the barcode to an array of lines where 0 is white and 1 is black.
-
#initialize(data) ⇒ DataMatrix
constructor
A new instance of DataMatrix.
-
#to_s ⇒ String
The data being encoded.
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
#data ⇒ Object
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
#bit?(x, y) ⇒ Boolean
NOTE: this method is not exposed via the gem so using send ahead of opening a PR to hopefully support:
github.com/mtgrosser/dmtx/blob/master/lib/dmtx/data_matrix.rb#L133-L135
66 67 68 |
# File 'lib/barby/barcode/data_matrix.rb', line 66 def bit?(x, y) encoder.send(:bit?, x, y) end |
#encoder ⇒ Object
23 24 25 |
# File 'lib/barby/barcode/data_matrix.rb', line 23 def encoder @encoder ||= ::Dmtx::DataMatrix.new(data) end |
#encoding ⇒ String
Converts the barcode to an array of lines where 0 is white and 1 is black.
51 52 53 54 55 56 |
# File 'lib/barby/barcode/data_matrix.rb', line 51 def encoding width = encoder.width height = encoder.height height.times.map { |y| width.times.map { |x| bit?(x, y) ? '1' : '0' }.join } end |
#to_s ⇒ String
The data being encoded.
74 75 76 |
# File 'lib/barby/barcode/data_matrix.rb', line 74 def to_s data end |