Sha256: 55a4686cb41c31381b5953ba640b1a9e4052b22c50cd1bf13a90db705a12f96f

Contents?: true

Size: 1.99 KB

Versions: 2

Compression:

Stored size: 1.99 KB

Contents

module ViewModel
  class RdSapWrapper
    attr_reader :view_model, :schema_type

    def initialize(xml_doc, schema_type, additional_data = {})
      @schema_type = schema_type
      @view_model = build_view_model(xml_doc, schema_type)
      @summary = Presenter::RdSap::Summary.new(view_model)
      @report = Presenter::RdSap::Report.new(view_model, schema_type, additional_data)
      @recommendation_report = Presenter::RdSap::RecommendationReport.new(view_model)
      @hera = Presenter::RdSap::Hera.new(view_model, schema_type)
    end

    def type
      :RdSAP
    end

    def to_hash
      @summary.to_hash
    end

    def to_hash_ni
      @report.to_hash_ni
    end

    def to_report
      @report.to_hash
    end

    def to_recommendation_report
      @recommendation_report.to_hash
    end

    def to_hera_hash
      @hera.to_hera_hash
    end

    def get_view_model
      view_model
    end

  private

    def build_view_model(xml_doc, schema_type)
      case schema_type
      when :"RdSAP-Schema-20.0.0"
        ViewModel::RdSapSchema200::CommonSchema.new xml_doc
      when :"RdSAP-Schema-19.0"
        ViewModel::RdSapSchema190::CommonSchema.new xml_doc
      when :"RdSAP-Schema-18.0"
        ViewModel::RdSapSchema180::CommonSchema.new xml_doc
      when :"RdSAP-Schema-17.1"
        ViewModel::RdSapSchema171::CommonSchema.new xml_doc
      when :"RdSAP-Schema-17.0"
        ViewModel::RdSapSchema170::CommonSchema.new xml_doc
      when :"RdSAP-Schema-NI-20.0.0"
        ViewModel::RdSapSchemaNi200::CommonSchema.new xml_doc
      when :"RdSAP-Schema-NI-19.0"
        ViewModel::RdSapSchemaNi190::CommonSchema.new xml_doc
      when :"RdSAP-Schema-NI-18.0"
        ViewModel::RdSapSchemaNi180::CommonSchema.new xml_doc
      when :"RdSAP-Schema-NI-17.4"
        ViewModel::RdSapSchemaNi174::CommonSchema.new xml_doc
      when :"RdSAP-Schema-NI-17.3"
        ViewModel::RdSapSchemaNi173::CommonSchema.new xml_doc
      else
        raise ArgumentError, "Unsupported schema type"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
epb_view_models-1.0.19 lib/view_model/rd_sap_wrapper.rb
epb_view_models-1.0.18 lib/view_model/rd_sap_wrapper.rb