Sha256: d1fcd1a20a36e9f192a6791a4d8b3d201f0814b6b0bb325188a0d4da940b419a

Contents?: true

Size: 1.87 KB

Versions: 14

Compression:

Stored size: 1.87 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)
    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 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

14 entries across 14 versions & 1 rubygems

Version Path
epb_view_models-1.0.16 lib/view_model/rd_sap_wrapper.rb
epb_view_models-1.0.15 lib/view_model/rd_sap_wrapper.rb
epb_view_models-1.0.14 lib/view_model/rd_sap_wrapper.rb
epb_view_models-1.0.13 lib/view_model/rd_sap_wrapper.rb
epb_view_models-1.0.12 lib/view_model/rd_sap_wrapper.rb
epb_view_models-1.0.11 lib/view_model/rd_sap_wrapper.rb
epb_view_models-1.0.10 lib/view_model/rd_sap_wrapper.rb
epb_view_models-1.0.9 lib/view_model/rd_sap_wrapper.rb
epb_view_models-1.0.8 lib/view_model/rd_sap_wrapper.rb
epb_view_models-1.0.7 lib/view_model/rd_sap_wrapper.rb
epb_view_models-1.0.6 lib/view_model/rd_sap_wrapper.rb
epb_view_models-1.0.5 lib/view_model/rd_sap_wrapper.rb
epb_view_models-1.0.4 lib/view_model/rd_sap_wrapper.rb
epb_view_models-1.0.3 lib/view_model/rd_sap_wrapper.rb