class Nfe::Models::Taxes::ICMS

Attributes

cst[RW]
modBC[RW]
modBCST[RW]
motDesICMS[RW]
orig[RW]
pCredSN[RW]
pICMS[RW]
pICMSST[RW]
pMVAST[RW]
pRedBC[RW]
pRedBCST[RW]
vBC[RW]
vBCST[RW]
vBCSTRet[RW]
vCredICMSSN[RW]
vICMS[RW]
vICMSDeson[RW]
vICMSST[RW]
vICMSSTRet[RW]

Public Class Methods

attr_icms() click to toggle source
# File lib/nfe/models/taxes/ICMS.rb, line 7
def self.attr_icms
  [:orig, :csosn, :cst, :modBC, :vBC, :pRedBC, :pICMS, :vICMS, :modBCST,
    :pMVAST, :pRedBCST, :vBCST, :pICMSST, :vICMSST, :pCredSN,
    :vCredICMSSN, :motDesICMS, :vBCSTRet, :vICMSSTRet, :vICMSDeson]
end
cst_types() click to toggle source
# File lib/nfe/models/taxes/ICMS.rb, line 13
def self.cst_types
  ["00", "10", "20", "30", "40", "41", "50", "51", "60",
    "70", "90", "101", "102", "103", "300", "400", "201", "202", "203", "500",
    "900"]
end

Public Instance Methods

parse!(xml) click to toggle source
# File lib/nfe/models/taxes/ICMS.rb, line 36
def parse!(xml)
  doc = Nokogiri::XML(xml)
  reset_values
  parse_xml(doc)
end
present?() click to toggle source
# File lib/nfe/models/taxes/ICMS.rb, line 29
def present?
  [@orig, @cst, @modBC, @vBC, @pRedBC, @pICMS, @vICMS, @modBCST,
    @pMVAST, @pRedBCST, @vBCST, @pICMSST, @vICMSST, @pCredSN,
    @vCredICMSSN, @motDesICMS, @vBCSTRet, @vICMSSTRet].
      reduce(false) {|memo, obj| memo || obj.present?}
end
to_xml() click to toggle source
# File lib/nfe/models/taxes/ICMS.rb, line 42
def to_xml
  xml = Builder::XmlMarkup.new

  to_object_xml(xml)

  xml.target!
end

Private Instance Methods

attribute_to_object(object) click to toggle source
# File lib/nfe/models/taxes/ICMS.rb, line 64
def attribute_to_object(object)
  self.class.attr_icms.each do |attribute|
    if object.respond_to? "#{attribute}="
      object.send("#{attribute}=", send(attribute))
    end
  end
end
object_to_attribute(object) click to toggle source
# File lib/nfe/models/taxes/ICMS.rb, line 86
def object_to_attribute(object)
  self.class.attr_icms.each do |attribute|
    if object.respond_to? "#{attribute}"
      send("#{attribute}=", object.send(attribute))
    end
  end
end
parse_xml(doc) click to toggle source
# File lib/nfe/models/taxes/ICMS.rb, line 72
def parse_xml(doc)
  self.class.cst_types.each do |cst|
    icms_type = Taxes::const_get("ICMS#{cst}")

    if doc.css(icms_type.root_name).present?
      icms = icms_type.new

      icms.parse! doc.css(icms_type.root_name).to_xml

      object_to_attribute icms
    end
  end
end
reset_values() click to toggle source
# File lib/nfe/models/taxes/ICMS.rb, line 94
def reset_values
  self.class.attr_icms.each { |attribute| send("#{attribute}=", nil) }
end
to_object_xml(xml) click to toggle source
# File lib/nfe/models/taxes/ICMS.rb, line 51
def to_object_xml(xml)
  icms_type = Taxes::const_get("ICMS#{@cst}")

  if icms_type

    icms = icms_type.new

    attribute_to_object icms

    xml.tag!(icms_type.root_name) { |node| node << icms.to_xml }
  end
end