Module: Nfe::Helpers::XmlModel::NfeModel
- Included in:
- Models::Avulsa, Models::Bill::Cobr, Models::Bill::Dup, Models::Bill::Fat, Models::Cane::Cana, Models::Cane::Deduc, Models::Cane::ForDia, Models::Compra, Models::Det, Models::Emitter::Emit, Models::Ender, Models::EntregaRetirada, Models::Evento, Models::Exporta, Models::Ide, Models::InfNFe, Models::Information::InfAdic, Models::Information::ObsContFisco, Models::Information::ProcRef, Models::Itens::Adi, Models::Itens::Arma, Models::Itens::CIDE, Models::Itens::Comb, Models::Itens::DI, Models::Itens::Med, Models::Itens::Prod, Models::Itens::VeicProd, Models::NFe, Models::NFeProc, Models::ProcEventoNFe, Models::ProcInutNFe, Models::Recipient::Dest, Models::Referenced::NFref, Models::Referenced::RefECF, Models::Referenced::RefNF, Models::Referenced::RefNFP, Models::Taxes::ICMSBase, Models::Taxes::ICMSPart, Models::Taxes::ICMSST, Models::Taxes::ICMSTot, Models::Taxes::II, Models::Taxes::IPI, Models::Taxes::IPINT, Models::Taxes::IPITrib, Models::Taxes::ISSQN, Models::Taxes::ISSQNtot, Models::Taxes::Imposto, Models::Taxes::PISCOFINSNT, Models::Taxes::PISCOFINSOutr, Models::Taxes::RetTrib, Models::Total, Models::Transport::Lacres, Models::Transport::RetTransp, Models::Transport::Transp, Models::Transport::Transporta, Models::Transport::VeicTranspReboque, Models::Transport::Vol, Services::Dispatch::ConsCad, Services::Dispatch::ConsStatServ, Services::Dispatch::DetEventoCC, Services::Dispatch::DetEventoCancel, Services::Dispatch::EnvEvento, Services::Dispatch::EnviNFe, Services::Dispatch::InutNFe, Services::Regress::InfCad, Services::Regress::RetConsCad, Services::Regress::RetConsSitNFe, Services::Regress::RetConsStatServ, Services::Regress::RetEnvEvento, Services::Regress::RetEnviNFe, Services::Regress::RetEvento, Services::Regress::RetInutNFe
- Defined in:
- lib/nfe/helpers/xml_model/nfe_model.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #add_elements(xml, *elements) ⇒ Object
- #check_present ⇒ Object
- #parse!(xml) ⇒ Object
- #parse_elements(doc, *elements) ⇒ Object
- #present? ⇒ Boolean
- #to_xml ⇒ Object
- #validate_optional_attributes(*attributes) ⇒ Object
- #validate_required_attributes(*attributes) ⇒ Object
Class Method Details
.included(base) ⇒ Object
5 6 7 |
# File 'lib/nfe/helpers/xml_model/nfe_model.rb', line 5 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#add_elements(xml, *elements) ⇒ Object
71 72 73 74 75 |
# File 'lib/nfe/helpers/xml_model/nfe_model.rb', line 71 def add_elements(xml, *elements) elements = get_elements(elements) Array(elements).each { |attribute| add_element xml, attribute } end |
#check_present ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/nfe/helpers/xml_model/nfe_model.rb', line 43 def check_present present = false self.class.xml_attributes.each do |key, value| present ||= value_present? key, value end present end |
#parse!(xml) ⇒ Object
51 52 53 |
# File 'lib/nfe/helpers/xml_model/nfe_model.rb', line 51 def parse!(xml) parse_elements xml end |
#parse_elements(doc, *elements) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/nfe/helpers/xml_model/nfe_model.rb', line 63 def parse_elements(doc, *elements) doc = Nokogiri::XML(doc) if doc.is_a? String elements = get_elements(elements) Array(elements).each { |attribute| parse_value doc, attribute } end |
#present? ⇒ Boolean
39 40 41 |
# File 'lib/nfe/helpers/xml_model/nfe_model.rb', line 39 def present? check_present end |
#to_xml ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/nfe/helpers/xml_model/nfe_model.rb', line 55 def to_xml xml = Builder::XmlMarkup.new add_elements xml xml.target! end |
#validate_optional_attributes(*attributes) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/nfe/helpers/xml_model/nfe_model.rb', line 77 def validate_optional_attributes(*attributes) attributes.each do |attribute| Array(send(attribute)).each do |item| if item.present? && !item.valid? errors.add(attribute, :invalid) unless errors.include?(attribute) end end end end |
#validate_required_attributes(*attributes) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/nfe/helpers/xml_model/nfe_model.rb', line 87 def validate_required_attributes(*attributes) attributes.each do |attribute| if !send(attribute).valid? errors.add(attribute, :invalid) unless errors.include?(attribute) end end end |