Class: Nfe::Helpers::SchemaValidator
- Inherits:
-
Object
- Object
- Nfe::Helpers::SchemaValidator
- Extended by:
- ActiveModel::Naming
- Defined in:
- lib/nfe/helpers/schema_validator.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
-
#initialize(schema_path, xml) ⇒ SchemaValidator
constructor
A new instance of SchemaValidator.
- #valid? ⇒ Boolean
Constructor Details
#initialize(schema_path, xml) ⇒ SchemaValidator
Returns a new instance of SchemaValidator.
8 9 10 11 12 |
# File 'lib/nfe/helpers/schema_validator.rb', line 8 def initialize(schema_path, xml) @document = Nokogiri::XML(xml) @xsd = Nokogiri::XML::Schema(File.open(schema_path)) @errors = ActiveModel::Errors.new(self) end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/nfe/helpers/schema_validator.rb', line 6 def errors @errors end |
Instance Method Details
#valid? ⇒ Boolean
14 15 16 17 18 19 20 21 |
# File 'lib/nfe/helpers/schema_validator.rb', line 14 def valid? @xsd.validate(@document).each do |error| = error..gsub("{http://www.portalfiscal.inf.br/nfe}", "") @errors.add(:base, ) unless @errors.added? :base, end @errors.empty? end |