Class: FE::Document::Issuer

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/facturacr/document/issuer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Issuer

Returns a new instance of Issuer.



20
21
22
23
24
25
26
27
28
# File 'lib/facturacr/document/issuer.rb', line 20

def initialize(args={})
  @name = args[:name]
  @identification_document = args[:identification_document]
  @comercial_name = args[:comercial_name]
  @location = args[:location]
  @phone = args[:phone]
  @fax = args[:fax]
  @email = args[:email]          
end

Instance Attribute Details

#comercial_nameObject

Returns the value of attribute comercial_name.



12
13
14
# File 'lib/facturacr/document/issuer.rb', line 12

def comercial_name
  @comercial_name
end

#emailObject

Returns the value of attribute email.



12
13
14
# File 'lib/facturacr/document/issuer.rb', line 12

def email
  @email
end

#faxObject

Returns the value of attribute fax.



12
13
14
# File 'lib/facturacr/document/issuer.rb', line 12

def fax
  @fax
end

#identification_documentObject

Returns the value of attribute identification_document.



12
13
14
# File 'lib/facturacr/document/issuer.rb', line 12

def identification_document
  @identification_document
end

#locationObject

Returns the value of attribute location.



12
13
14
# File 'lib/facturacr/document/issuer.rb', line 12

def location
  @location
end

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/facturacr/document/issuer.rb', line 12

def name
  @name
end

#phoneObject

Returns the value of attribute phone.



12
13
14
# File 'lib/facturacr/document/issuer.rb', line 12

def phone
  @phone
end

Instance Method Details

#build_xml(node) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/facturacr/document/issuer.rb', line 30

def build_xml(node)  
  raise "IdentificationDocument is invalid" if @identification_document.nil? || !@identification_document.is_a?(IdentificationDocument)
  raise "Location is invalid" if @location.nil? || !@location.is_a?(Location)
  raise "Phone is invalid" if !@phone.nil? && !@phone.is_a?(Phone)
  raise "Fax is invalid" if !@fax.nil? && !@fax.is_a?(Fax)
  
  raise "Issuer is invalid: #{errors.messages}" unless valid?
   
  node = Nokogiri::XML::Builder.new if node.nil?
  node.Emisor do |xml|
    xml.Nombre @name
    identification_document.build_xml(xml)
    xml.NombreComercial @comercial_name if @comercial_name
    location.build_xml(xml)
    phone.build_xml(xml) if phone.present?
    fax.build_xml(xml) if fax.present?
    xml.CorreoElectronico @email
  end          
end

#to_xml(builder) ⇒ Object



50
51
52
# File 'lib/facturacr/document/issuer.rb', line 50

def to_xml(builder)
  build_xml(builder).to_xml
end