Class: BrDanfe::DanfeLib::NfeLib::Dup

Inherits:
Object
  • Object
show all
Defined in:
lib/br_danfe/danfe_lib/nfe_lib/dup.rb

Constant Summary collapse

Y_POSITION =
12.92
DUP_MAX_QUANTITY =
12

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pdf, xml) ⇒ Dup

Returns a new instance of Dup.



10
11
12
13
14
15
16
17
# File 'lib/br_danfe/danfe_lib/nfe_lib/dup.rb', line 10

def initialize(pdf, xml)
  @pdf = pdf
  @xml = xml

  @y_position = Entrega.delivery_local?(@xml) ? Y_POSITION + 3.00 : Y_POSITION

  @ltitle = @y_position - 0.42
end

Instance Attribute Details

#y_positionObject (readonly)

Returns the value of attribute y_position.



5
6
7
# File 'lib/br_danfe/danfe_lib/nfe_lib/dup.rb', line 5

def y_position
  @y_position
end

Instance Method Details

#renderObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/br_danfe/danfe_lib/nfe_lib/dup.rb', line 19

def render
  x = 0.75
  y = @y_position

  @pdf.ititle 0.42, 10.00, x, @ltitle, 'dup.title'

  render_titles_and_box(x, y)

  @xml.collect('xmlns', 'dup') { _1 }[..(DUP_MAX_QUANTITY - 1)].each_with_index do |det, index|
    x = 0.75 unless index != DUP_MAX_QUANTITY / 2

    y = if index < DUP_MAX_QUANTITY / 2
          @y_position - 0.015
        else
          @y_position + 0.185
        end

    render_dup(det, x, y + 0.3)
    x += 3.261666667
  end
end