Class: Ksef::UPO::Validation

Inherits:
Data
  • Object
show all
Defined in:
lib/ksef/upo/validation.rb

Overview

The outcome of checking a UPO against the bundled schema (docs/REFERENCE.md §14.3).

Two lists rather than one, because a UPO has a category of schema violation that is upstream's fault and expected: upo-v4-3.xsd fixes the receiving party's name to "Ministerstwo Finansów", while every non-production environment appends a marker. All six of upstream's own worked examples fail upstream's own schema on exactly that element, and nothing else.

So those go in #warnings and everything else in #errors, and #valid? ignores the warnings. A validator that reported them as errors would reject every UPO that TEST and DEMO issue — which is the trap this gem would otherwise have walked into, having already built strict XSD validation for FA(3).

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errors ⇒ Object (readonly)

Returns the value of attribute errors

Returns:

  • (Object) —

    the current value of errors



17
18
19
# File 'lib/ksef/upo/validation.rb', line 17

def errors
  @errors
end

#receiving_party ⇒ Object (readonly)

Returns the value of attribute receiving_party

Returns:

  • (Object) —

    the current value of receiving_party



17
18
19
# File 'lib/ksef/upo/validation.rb', line 17

def receiving_party
  @receiving_party
end

#warnings ⇒ Object (readonly)

Returns the value of attribute warnings

Returns:

  • (Object) —

    the current value of warnings



17
18
19
# File 'lib/ksef/upo/validation.rb', line 17

def warnings
  @warnings
end

Instance Method Details

#clean? ⇒ Boolean

True when the document also matched the fixed value — which in practice means it came from production, or from an environment that has stopped appending a marker.

Returns:

  • (Boolean)


23
# File 'lib/ksef/upo/validation.rb', line 23

def clean? = errors.empty? && warnings.empty?

#environment_marked? ⇒ Boolean

True when the only complaint was the known upstream defect.

Returns:

  • (Boolean)


26
# File 'lib/ksef/upo/validation.rb', line 26

def environment_marked? = errors.empty? && !warnings.empty?

#messages ⇒ Object



28
# File 'lib/ksef/upo/validation.rb', line 28

def messages = errors + warnings

#to_s ⇒ Object



30
31
32
33
34
# File 'lib/ksef/upo/validation.rb', line 30

def to_s
  return "valid" if clean?

  "#{errors.size} error(s), #{warnings.size} warning(s)"
end

#valid? ⇒ Boolean

True when nothing but the expected environment-marker discrepancy was found.

Returns:

  • (Boolean)


19
# File 'lib/ksef/upo/validation.rb', line 19

def valid? = errors.empty?