Sha256: 774e646834a6ed51cbe5d82a2d12247492bcd9c7e781ddbfc7399bdeb7f657ab

Contents?: true

Size: 1.22 KB

Versions: 43

Compression:

Stored size: 1.22 KB

Contents

module ViewModel
  class DecSummaryWrapper
    class AssessmentNotSupported < StandardError
    end

    TYPE_OF_ASSESSMENT = "DEC".freeze
    private_constant :TYPE_OF_ASSESSMENT
    attr_reader :view_model

    def initialize(xml, schema_type)
      # Hack to use symbols, we need to update all callers to use symbols instead
      schema_type = schema_type.to_sym

      # FIXME: For some reasons the XML is received as a string and not a Nokogiri Document (like other wrappers)
      xml_doc = Nokogiri.XML(xml).remove_namespaces!
      @view_model = build_view_model(xml_doc, schema_type)
      @xml_summary = Presenter::Dec::XmlSummary.new(view_model)
    end

    def type
      :DEC
    end

    def to_xml
      @xml_summary.to_xml
    end

  private

    def build_view_model(xml_doc, schema_type)
      case schema_type
      when :"CEPC-8.0.0"
        ViewModel::Cepc800::Dec.new xml_doc
      when :"CEPC-NI-8.0.0"
        ViewModel::CepcNi800::Dec.new xml_doc
      when :"CEPC-7.1"
        ViewModel::Cepc71::Dec.new xml_doc
      when :"CEPC-7.0"
        ViewModel::Cepc70::Dec.new xml_doc
      when :"CEPC-6.0"
        ViewModel::Cepc60::Dec.new xml_doc
      else
        raise AssessmentNotSupported
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
epb_view_models-2.0.1 lib/view_model/dec_summary_wrapper.rb
epb_view_models-2.0.0 lib/view_model/dec_summary_wrapper.rb
epb_view_models-1.2.3 lib/view_model/dec_summary_wrapper.rb
epb_view_models-1.2.2 lib/view_model/dec_summary_wrapper.rb
epb_view_models-1.2.1 lib/view_model/dec_summary_wrapper.rb
epb_view_models-1.2.0 lib/view_model/dec_summary_wrapper.rb
epb_view_models-1.1.6 lib/view_model/dec_summary_wrapper.rb
epb_view_models-1.1.5 lib/view_model/dec_summary_wrapper.rb
epb_view_models-1.1.4 lib/view_model/dec_summary_wrapper.rb
epb_view_models-1.1.3 lib/view_model/dec_summary_wrapper.rb
epb_view_models-1.1.2 lib/view_model/dec_summary_wrapper.rb
epb_view_models-1.1.1 lib/view_model/dec_summary_wrapper.rb
epb_view_models-1.1.0 lib/view_model/dec_summary_wrapper.rb
epb_view_models-1.0.29 lib/view_model/dec_summary_wrapper.rb
epb_view_models-1.0.28 lib/view_model/dec_summary_wrapper.rb
epb_view_models-1.0.27 lib/view_model/dec_summary_wrapper.rb
epb_view_models-1.0.26 lib/view_model/dec_summary_wrapper.rb
epb_view_models-1.0.25 lib/view_model/dec_summary_wrapper.rb
epb_view_models-1.0.24 lib/view_model/dec_summary_wrapper.rb
epb_view_models-1.0.23 lib/view_model/dec_summary_wrapper.rb