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.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
-
#xsd_path ⇒ Object
readonly
Returns the value of attribute xsd_path.
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(template: nil, xsd_path: nil, locals: {}) ⇒ XmlRenderer
constructor
A new instance of XmlRenderer.
-
#validation_errors ⇒ Object
Returns an array of SchemaValidation errors.
- #xml ⇒ Object
Constructor Details
#initialize(template: nil, xsd_path: nil, locals: {}) ⇒ XmlRenderer
Returns a new instance of XmlRenderer.
19 20 21 22 23 |
# File 'app/models/renalware/ukrdc/xml_renderer.rb', line 19 def initialize(template: nil, xsd_path: nil, locals: {}) @template = template || DEFAULT_TEMPLATE @xsd_path = xsd_path || default_xsd_path @locals = locals end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
9 10 11 |
# File 'app/models/renalware/ukrdc/xml_renderer.rb', line 9 def errors @errors end |
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
9 10 11 |
# File 'app/models/renalware/ukrdc/xml_renderer.rb', line 9 def locals @locals end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
9 10 11 |
# File 'app/models/renalware/ukrdc/xml_renderer.rb', line 9 def template @template end |
#xsd_path ⇒ Object (readonly)
Returns the value of attribute xsd_path.
9 10 11 |
# File 'app/models/renalware/ukrdc/xml_renderer.rb', line 9 def xsd_path @xsd_path 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.
29 30 31 32 33 |
# File 'app/models/renalware/ukrdc/xml_renderer.rb', line 29 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
47 48 49 50 51 52 53 54 |
# File 'app/models/renalware/ukrdc/xml_renderer.rb', line 47 def validation_errors @validation_errors ||= begin document = Nokogiri::XML(xml) xsddoc = Nokogiri::XML(File.read(xsd_path), xsd_path) schema = Nokogiri::XML::Schema.from_document(xsddoc) schema.validate(document) end end |
#xml ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/renalware/ukrdc/xml_renderer.rb', line 35 def xml @xml ||= begin API::UKRDC::PatientsController.new.render_to_string( template: template, format: :xml, locals: locals, encoding: "UTF-8" ) end end |