Class: Croatia::PDF417

Inherits:
Object
  • Object
show all
Defined in:
lib/croatia/pdf417.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, **options) ⇒ PDF417

Returns a new instance of PDF417.



16
17
18
19
# File 'lib/croatia/pdf417.rb', line 16

def initialize(data, **options)
  @data = data
  @options = options
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



14
15
16
# File 'lib/croatia/pdf417.rb', line 14

def data
  @data
end

#optionsObject (readonly)

Returns the value of attribute options.



14
15
16
# File 'lib/croatia/pdf417.rb', line 14

def options
  @options
end

Class Method Details

.ensure_supported!Object

Raises:

  • (LoadError)


4
5
6
7
8
# File 'lib/croatia/pdf417.rb', line 4

def self.ensure_supported!
  return if supported?

  raise LoadError, "Zint library is not loaded. Please ensure you have the ruby-zint gem installed and required."
end

.supported?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/croatia/pdf417.rb', line 10

def self.supported?
  defined?(Zint)
end

Instance Method Details

#to_png(**options) ⇒ Object



39
40
41
# File 'lib/croatia/pdf417.rb', line 39

def to_png(**options)
  barcode.to_memory_file(extension: ".png")
end

#to_svg(**options) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/croatia/pdf417.rb', line 21

def to_svg(**options)
  vec = barcode.to_vector

  foreground_color = options[:foreground_color] || "black"
  background_color = options[:background_color] || "white"

  svg = []
  svg << %Q(<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="#{vec.width.to_i}" height="#{vec.height.to_i}" viewBox="0 0 #{vec.width.to_i} #{vec.height.to_i}">)
  svg << %Q(<rect width="#{vec.width.to_i}" height="#{vec.height.to_i}" fill="#{background_color}" />)

  vec.each_rectangle do |rect|
    svg << %Q(<rect x="#{rect.x.to_i}" y="#{rect.y.to_i}" width="#{rect.width.to_i}" height="#{rect.height.to_i}" fill="#{foreground_color}" />)
  end

  svg << "</svg>"
  svg.join("\n")
end