Class: Barby::Outputter
- Inherits:
-
Object
- Object
- Barby::Outputter
- Defined in:
- lib/barby/outputter.rb
Overview
An Outputter creates something from a barcode. That something can be anything, but is most likely a graphical representation of the barcode. Outputters can register methods on barcodes that will be associated with them.
The basic structure of an outputter class:
class FooOutputter < Barby::Outputter
register :to_foo
def to_too
do_something_with(.encoding)
end
end
Barcode#to_foo will now be available to all barcodes
Direct Known Subclasses
ASCIIOutputter, CairoOutputter, PDFWriterOutputter, PngOutputter, PrawnOutputter, RmagickOutputter, SvgOutputter
Instance Attribute Summary collapse
-
#barcode ⇒ Object
Returns the value of attribute barcode.
Class Method Summary collapse
-
.register(*method_names) ⇒ Object
Register one or more handler methods with this outputter Barcodes will then be able to use these methods to get the output from the outputter.
Instance Method Summary collapse
-
#initialize(barcode) ⇒ Outputter
constructor
An outputter instance will have access to a Barcode.
Constructor Details
#initialize(barcode) ⇒ Outputter
An outputter instance will have access to a Barcode
27 28 29 |
# File 'lib/barby/outputter.rb', line 27 def initialize() self. = end |
Instance Attribute Details
#barcode ⇒ Object
Returns the value of attribute barcode.
23 24 25 |
# File 'lib/barby/outputter.rb', line 23 def @barcode end |
Class Method Details
.register(*method_names) ⇒ Object
Register one or more handler methods with this outputter Barcodes will then be able to use these methods to get the output from the outputter. For example, if you have an ImageOutputter, you could do:
register :to_png, :to_gif
You could then do aBarcode.to_png and get the result of that method. The class which registers the method will receive the barcode as the only argument, and the default implementation of initialize puts that into the barcode
accessor.
You can also have different method names on the barcode and the outputter by providing a hash:
register :to_png => :create_png, :to_gif => :create_gif
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/barby/outputter.rb', line 48 def self.register(*method_names) if method_names.first.is_a? Hash method_names.first.each do |name, method_name| Barcode.register_outputter(name, self, method_name) end else method_names.each do |name| Barcode.register_outputter(name, self, name) end end end |