Class: Ticketbai::DocumentValidator
- Inherits:
-
Object
- Object
- Ticketbai::DocumentValidator
- Defined in:
- lib/ticketbai/document_validator.rb
Constant Summary collapse
- SUPPORTED_VALIDATORS =
[Operations::Issuance::OPERATION_NAME, Operations::Annulment::OPERATION_NAME].freeze
Instance Attribute Summary collapse
-
#document ⇒ Object
Returns the value of attribute document.
-
#validator_type ⇒ Object
Returns the value of attribute validator_type.
Instance Method Summary collapse
-
#initialize(document:, validator_type:) ⇒ DocumentValidator
constructor
A new instance of DocumentValidator.
-
#validate ⇒ Object
Raises an exception with the validation error(s).
Constructor Details
#initialize(document:, validator_type:) ⇒ DocumentValidator
Returns a new instance of DocumentValidator.
11 12 13 14 15 16 |
# File 'lib/ticketbai/document_validator.rb', line 11 def initialize(document:, validator_type:) raise ArgumentError, 'Unsupported validator' unless SUPPORTED_VALIDATORS.include? validator_type.downcase.to_sym @document = document @validator_type = validator_type.downcase.to_sym end |
Instance Attribute Details
#document ⇒ Object
Returns the value of attribute document.
3 4 5 |
# File 'lib/ticketbai/document_validator.rb', line 3 def document @document end |
#validator_type ⇒ Object
Returns the value of attribute validator_type.
3 4 5 |
# File 'lib/ticketbai/document_validator.rb', line 3 def validator_type @validator_type end |
Instance Method Details
#validate ⇒ Object
Raises an exception with the validation error(s)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ticketbai/document_validator.rb', line 21 def validate errors = [] xsd_validator.validate(Nokogiri::XML(@document)).each do |error| errors << error. end return unless errors.any? raise Ticketbai::TBAIFileError.new( errors.uniq.join(','), 'TBAIFile' ) end |