class BrDanfe::DanfeLib::NfeLib::Entrega

Constants

MAXIMUM_SIZE_FOR_STREET
Y_POSITION

Public Class Methods

delivery_local?(xml) click to toggle source
# File lib/br_danfe/danfe_lib/nfe_lib/entrega.rb, line 28
def self.delivery_local?(xml)
  doc = xml.is_a?(BrDanfe::XML) ? xml : Nokogiri::XML(xml)
  doc.css('entrega/xLgr').text.present?
end
new(pdf, xml) click to toggle source
# File lib/br_danfe/danfe_lib/nfe_lib/entrega.rb, line 8
def initialize(pdf, xml)
  @pdf = pdf
  @xml = xml

  @y_position = Y_POSITION
  @ltitle = @y_position - 0.42
  @l1 = @y_position
  @l2 = @y_position + LINE_HEIGHT
  @l3 = @y_position + (LINE_HEIGHT * 2)
end

Public Instance Methods

render() click to toggle source
# File lib/br_danfe/danfe_lib/nfe_lib/entrega.rb, line 19
def render
  if Entrega.delivery_local?(@xml)
    @pdf.ititle 0.42, 10.00, 0.75, @ltitle, 'entrega.title'
    render_line1
    render_line2
    render_line3
  end
end

Private Instance Methods

address() click to toggle source
# File lib/br_danfe/danfe_lib/nfe_lib/entrega.rb, line 60
def address
  address = Helper.generate_address @xml, 'entrega'

  if Helper.address_is_too_big(@pdf, address)
    address = address[0..address.length - 2] while Helper.mensure_text(@pdf, "#{address.strip}...") > MAXIMUM_SIZE_FOR_STREET && !address.empty?
    address = "#{address.strip}..."
  end
  address
end
cep() click to toggle source
# File lib/br_danfe/danfe_lib/nfe_lib/entrega.rb, line 70
def cep
  BrDanfe::Helper.format_cep(@xml['entrega/CEP'])
end
cpf() click to toggle source
# File lib/br_danfe/danfe_lib/nfe_lib/entrega.rb, line 49
def cpf
  cpf = BrDocuments::CnpjCpf::Cpf.new(@xml['entrega/CPF'])
  cpf.formatted
end
phone() click to toggle source
# File lib/br_danfe/danfe_lib/nfe_lib/entrega.rb, line 80
def phone
  Phone.format(@xml['entrega/fone'])
end
render_cnpj_cpf() click to toggle source
# File lib/br_danfe/danfe_lib/nfe_lib/entrega.rb, line 41
def render_cnpj_cpf
  if @xml['entrega/CNPJ'] == ''
    @pdf.i18n_lbox LINE_HEIGHT, 4.37, 12.57, @l1, 'entrega.CPF', cpf
  else
    @pdf.lcnpj LINE_HEIGHT, 4.37, 12.57, @l1, @xml, 'entrega/CNPJ'
  end
end
render_line1() click to toggle source
# File lib/br_danfe/danfe_lib/nfe_lib/entrega.rb, line 35
def render_line1
  @pdf.lbox LINE_HEIGHT, 11.82, 0.75, @l1, @xml, 'entrega/xNome'
  render_cnpj_cpf
  @pdf.lie LINE_HEIGHT, 2.92, 17.40, @l1, @xml, 'entrega/UF', 'entrega/IE'
end
render_line2() click to toggle source
# File lib/br_danfe/danfe_lib/nfe_lib/entrega.rb, line 54
def render_line2
  @pdf.i18n_lbox LINE_HEIGHT, 11.82, 0.75, @l2, 'entrega.xLgr', address
  @pdf.lbox LINE_HEIGHT, 4.37, 12.57, @l2, @xml, 'entrega/xBairro'
  @pdf.i18n_lbox LINE_HEIGHT, 2.92, 17.40, @l2, 'entrega.CEP', cep
end
render_line3() click to toggle source
# File lib/br_danfe/danfe_lib/nfe_lib/entrega.rb, line 74
def render_line3
  @pdf.lbox LINE_HEIGHT, 15.05, 0.75, @l3, @xml, 'entrega/xMun'
  @pdf.lbox LINE_HEIGHT, 1.14, 15.8, @l3, @xml, 'entrega/UF'
  @pdf.i18n_lbox LINE_HEIGHT, 2.92, 17.40, @l3, 'entrega.fone', phone
end