class ViewModel::Factory
Constants
- TYPES_OF_CEPC
- TYPES_OF_RD_SAP
- TYPES_OF_SAP
Public Instance Methods
create(xml, schema_type, filter_results_for = nil, additional_data = {})
click to toggle source
# File lib/view_model/factory.rb, line 61 def create(xml, schema_type, filter_results_for = nil, additional_data = {}) # Hack to use symbols, we need to update all callers to use symbols instead schema_type = schema_type.to_sym xml_doc = Nokogiri.XML(xml).remove_namespaces! if TYPES_OF_CEPC.include?(schema_type) filtered_results = if filter_results_for xml_doc.at("//*[RRN=\"#{filter_results_for}\"]/ancestor::Report") else xml_doc end report_type = filtered_results.at("Report-Type").content case report_type when "1" ViewModel::DecWrapper.new(filtered_results, schema_type, additional_data) when "2" ViewModel::DecRrWrapper.new(filtered_results, schema_type) when "3" ViewModel::CepcWrapper.new(filtered_results, schema_type, additional_data) when "4" ViewModel::CepcRrWrapper.new(filtered_results, schema_type) when "5" ViewModel::AcReportWrapper.new(filtered_results, schema_type) when "6" ViewModel::AcCertWrapper.new(filtered_results, schema_type) else raise ArgumentError, "Invalid CEPC report type" end elsif TYPES_OF_RD_SAP.include?(schema_type) ViewModel::RdSapWrapper.new(xml_doc, schema_type, additional_data) elsif TYPES_OF_SAP.include?(schema_type) report_type = xml_doc.at("Report-Type")&.content ViewModel::SapWrapper.new(xml_doc, schema_type, report_type, additional_data) end end