Class: Renalware::UKRDC::XmlRenderer
- Inherits:
-
Object
- Object
- Renalware::UKRDC::XmlRenderer
- Defined in:
- app/models/renalware/ukrdc/xml_renderer.rb
Defined Under Namespace
Constant Summary collapse
- DEFAULT_TEMPLATE =
"/renalware/api/ukrdc/patients/show"
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#locals ⇒ Object
readonly
Returns the value of attribute locals.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
-
#call ⇒ Object
If we successfully generate the UKRDC XML for a patient, return a Success object where success#xml is the valid XML If there are XSD validation messages, we return a Failure object where failure#validation_messages is an array of XSD validation messages.
-
#initialize(schema:, template: nil, locals: {}) ⇒ XmlRenderer
constructor
Schema is an instance of Nokogiri::XML::Schema passed in for optimisation reasons.
-
#validation_errors ⇒ Object
Returns an array of SchemaValidation errors.
- #xml ⇒ Object
Constructor Details
#initialize(schema:, template: nil, locals: {}) ⇒ XmlRenderer
Schema is an instance of Nokogiri::XML::Schema passed in for optimisation reasons. If it is not passed in we create it.
22 23 24 25 26 |
# File 'app/models/renalware/ukrdc/xml_renderer.rb', line 22 def initialize(schema:, template: nil, locals: {}) @template = template || DEFAULT_TEMPLATE @schema = schema @locals = locals end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
10 11 12 |
# File 'app/models/renalware/ukrdc/xml_renderer.rb', line 10 def errors @errors end |
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
10 11 12 |
# File 'app/models/renalware/ukrdc/xml_renderer.rb', line 10 def locals @locals end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
10 11 12 |
# File 'app/models/renalware/ukrdc/xml_renderer.rb', line 10 def schema @schema end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
10 11 12 |
# File 'app/models/renalware/ukrdc/xml_renderer.rb', line 10 def template @template end |
Instance Method Details
#call ⇒ Object
If we successfully generate the UKRDC XML for a patient, return a Success object where success#xml is the valid XML If there are XSD validation messages, we return a Failure object where failure#validation_messages is an array of XSD validation messages.
32 33 34 35 36 |
# File 'app/models/renalware/ukrdc/xml_renderer.rb', line 32 def call return XmlRenderer::Failure.new(validation_errors) if validation_errors.any? XmlRenderer::Success.new(xml) end |
#validation_errors ⇒ Object
Returns an array of SchemaValidation errors
49 50 51 |
# File 'app/models/renalware/ukrdc/xml_renderer.rb', line 49 def validation_errors @validation_errors ||= schema.validate(xml) end |