64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/view_model/factory.rb', line 64
def create(xml, schema_type, filter_results_for = nil, additional_data = {})
schema_type = schema_type.to_sym
xml_doc = Nokogiri.XML(xml, nil, nil, Nokogiri::XML::ParseOptions.new.huge.strict).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
|