Sha256: 193eaa5f125470a5a7860e3b3ae2bcb0448120eec46758e426d18b31d7e84854

Contents?: true

Size: 1.45 KB

Versions: 49

Compression:

Stored size: 1.45 KB

Contents

module ViewModel
  class CepcWrapper
    attr_reader :view_model

    def initialize(xml_doc, schema_type, additional_data = {})
      @view_model = build_view_model(xml_doc, schema_type)
      @summary = Presenter::Cepc::Summary.new(view_model)
      @report = Presenter::Cepc::Report.new(view_model, additional_data)
    end

    def type
      :CEPC
    end

    def to_hash
      @summary.to_hash
    end

    # create hash for data requested by Open Data Communities
    # hash keys will be turned into columns for expected csv
    def to_report
      @report.to_hash
    end

    def get_report_type
      view_model.report_type
    end

    def get_view_model
      view_model
    end

  private

    def build_view_model(xml_doc, schema_type)
      case schema_type
      when :"CEPC-8.0.0"
        ViewModel::Cepc800::Cepc.new xml_doc
      when :"CEPC-NI-8.0.0"
        ViewModel::CepcNi800::Cepc.new xml_doc
      when :"CEPC-7.1"
        ViewModel::Cepc71::Cepc.new xml_doc
      when :"CEPC-7.0"
        ViewModel::Cepc70::Cepc.new xml_doc
      when :"CEPC-6.0"
        ViewModel::Cepc60::Cepc.new xml_doc
      when :"CEPC-5.1"
        ViewModel::Cepc51::Cepc.new xml_doc
      when :"CEPC-5.0"
        ViewModel::Cepc50::Cepc.new xml_doc
      when :"CEPC-4.0"
        ViewModel::Cepc40::Cepc.new xml_doc
      when :"CEPC-3.1"
        ViewModel::Cepc31::Cepc.new xml_doc
      else
        raise ArgumentError, "Unsupported schema type"
      end
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
epb_view_models-2.0.7 lib/view_model/cepc_wrapper.rb
epb_view_models-2.0.6 lib/view_model/cepc_wrapper.rb
epb_view_models-2.0.5 lib/view_model/cepc_wrapper.rb
epb_view_models-2.0.4 lib/view_model/cepc_wrapper.rb
epb_view_models-2.0.3 lib/view_model/cepc_wrapper.rb
epb_view_models-2.0.2 lib/view_model/cepc_wrapper.rb
epb_view_models-2.0.1 lib/view_model/cepc_wrapper.rb
epb_view_models-2.0.0 lib/view_model/cepc_wrapper.rb
epb_view_models-1.2.3 lib/view_model/cepc_wrapper.rb
epb_view_models-1.2.2 lib/view_model/cepc_wrapper.rb
epb_view_models-1.2.1 lib/view_model/cepc_wrapper.rb
epb_view_models-1.2.0 lib/view_model/cepc_wrapper.rb
epb_view_models-1.1.6 lib/view_model/cepc_wrapper.rb
epb_view_models-1.1.5 lib/view_model/cepc_wrapper.rb
epb_view_models-1.1.4 lib/view_model/cepc_wrapper.rb
epb_view_models-1.1.3 lib/view_model/cepc_wrapper.rb
epb_view_models-1.1.2 lib/view_model/cepc_wrapper.rb
epb_view_models-1.1.1 lib/view_model/cepc_wrapper.rb
epb_view_models-1.1.0 lib/view_model/cepc_wrapper.rb
epb_view_models-1.0.29 lib/view_model/cepc_wrapper.rb