Class: ActionView::Base
- Inherits:
-
Object
- Object
- ActionView::Base
- Defined in:
- lib/barcoder.rb
Constant Summary collapse
- VALID_BARCODER_OPTIONS =
important defaults, should not be messed with.
[:encoding_format, :output_format, :width, :height, :scaling_factor, :xoff, :yoff, :margin, :output_type]
- DEFAULT_BARCODER_OUTPUT_FORMAT =
'gif'- DEFAULT_BARCODER_ENCODING =
Gbarcode::BARCODE_39 | Gbarcode::BARCODE_NO_CHECKSUM
- BARCODE_STORAGE_PATH =
"public/images/barcodes"
Instance Method Summary collapse
-
#barcode(str, options = {:encoding_format => DEFAULT_BARCODER_ENCODING }) ⇒ Object
support for the original barcode-generator plugin syntax.
- #to_barcode(str, options = {:encoding_format => DEFAULT_BARCODER_ENCODING }) ⇒ Object
Instance Method Details
#barcode(str, options = {:encoding_format => DEFAULT_BARCODER_ENCODING }) ⇒ Object
support for the original barcode-generator plugin syntax.
54 55 56 |
# File 'lib/barcoder.rb', line 54 def (str, = {:encoding_format => DEFAULT_BARCODER_ENCODING }) (str, ) end |
#to_barcode(str, options = {:encoding_format => DEFAULT_BARCODER_ENCODING }) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/barcoder.rb', line 21 def (str, = {:encoding_format => DEFAULT_BARCODER_ENCODING }) # verify requirements .assert_valid_keys(VALID_BARCODER_OPTIONS) output_format = [:output_format] ? [:output_format] : DEFAULT_BARCODER_OUTPUT_FORMAT output_type = [:output_type] ? [:output_type] : :stream # generate the barcode object with all supplied options [:encoding_format] = DEFAULT_BARCODER_ENCODING unless [:encoding_format] bc = Gbarcode.(str.to_s) bc.width = [:width] if [:width] bc.height = [:height] if [:height] bc.scalef = [:scaling_factor] if [:scaling_factor] bc.xoff = [:xoff] if [:xoff] bc.yoff = [:yoff] if [:yoff] bc.margin = [:margin] if [:margin] Gbarcode.(bc, [:encoding_format]) if [:no_ascii] = Gbarcode::BARCODE_OUT_EPS|Gbarcode::BARCODE_NO_ASCII else = Gbarcode::BARCODE_OUT_EPS end # this is where the magic happens. data = `echo "#{(bc, )}" | convert eps: #{output_format}:` # simple output strategy, define :output_type => :disk in the #to_barcode call if you want # it to write out to the disk for you, otherwise it will be a data url stream. output_type == :disk ? (data, bc, output_format) : (data, output_format, str) end |