Class: Nfe::Models::Taxes::PISCOFINSST

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/nfe/models/taxes/PISCOFINSST.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_tax, xml_value) ⇒ PISCOFINSST

Returns a new instance of PISCOFINSST.



44
45
46
47
# File 'lib/nfe/models/taxes/PISCOFINSST.rb', line 44

def initialize(xml_tax, xml_value)
  @xml_tax = xml_tax
  @xml_value = xml_value
end

Instance Attribute Details

#qBCProdObject

Returns the value of attribute qBCProd.



7
8
9
# File 'lib/nfe/models/taxes/PISCOFINSST.rb', line 7

def qBCProd
  @qBCProd
end

#taxObject

Returns the value of attribute tax.



7
8
9
# File 'lib/nfe/models/taxes/PISCOFINSST.rb', line 7

def tax
  @tax
end

#vAliqProdObject

Returns the value of attribute vAliqProd.



7
8
9
# File 'lib/nfe/models/taxes/PISCOFINSST.rb', line 7

def vAliqProd
  @vAliqProd
end

#valueObject

Returns the value of attribute value.



7
8
9
# File 'lib/nfe/models/taxes/PISCOFINSST.rb', line 7

def value
  @value
end

#vBCObject

Returns the value of attribute vBC.



7
8
9
# File 'lib/nfe/models/taxes/PISCOFINSST.rb', line 7

def vBC
  @vBC
end

Instance Method Details

#parse!(xml) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/nfe/models/taxes/PISCOFINSST.rb', line 54

def parse!(xml)
  doc = Nokogiri::XML(xml)

  @vBC = doc.css("vBC").present? ? doc.css("vBC").text.to_f : nil
  @tax = doc.css(@xml_tax).present? ? doc.css(@xml_tax).text.to_f : nil
  @qBCProd = doc.css("qBCProd").present? ? doc.css("qBCProd").text.to_f : nil
  @vAliqProd = doc.css("vAliqProd").present? ? doc.css("vAliqProd").text.to_f : nil
  @value = doc.css(@xml_value).text.to_f
end

#present?Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/nfe/models/taxes/PISCOFINSST.rb', line 49

def present?
  @vBC.present? || @tax.present? || @qBCProd.present? ||
    @vAliqProd.present? || @value.present?
end

#to_xmlObject



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/nfe/models/taxes/PISCOFINSST.rb', line 64

def to_xml
  xml = Builder::XmlMarkup.new

  xml.vBC "%0.2f" % @vBC if @vBC.present?
  xml.tag!(@xml_tax) { |node| node << "%0.2f" % @tax } if @tax.present?
  xml.qBCProd "%0.4f" % @qBCProd if @qBCProd.present?
  xml.vAliqProd "%0.4f" % @vAliqProd if @vAliqProd.present?
  xml.tag!(@xml_value) { |node| node << "%0.2f" % @value }

  xml.target!
end