Sha256: 188298fdb8a3b6cfae5ea5eaf54ba1bbc38420da4ae5b16316dff9799f6f019b

Contents?: true

Size: 1.26 KB

Versions: 10

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/ukrdc"
require "attr_extras"
require "benchmark"

module Renalware
  module UKRDC
    module TreatmentTimeline
      class GeneratorFactory
        DEFAULT_TYPE = "Generic"

        # Returns the class of object to suitable for generating the treatment timeline for the
        # requested modality. If the modality description type is nil then we use a generic
        # generator. If no generator class is defined matching the description.type, we also
        # return nil.
        # Example:
        # given the modality_description.type of Renalware::Bla::BlaModalityDescription
        # we will look to see if the constant GenerateBlaBlaTimeline exists and return an instance
        # if so - otherwise we return an instance of the default generator GenerateGenericTimeline.
        def self.call(modality)
          type = modality.description.type.presence || DEFAULT_TYPE
          type = type.gsub("::", "").gsub(/^Renalware/, "").gsub(/ModalityDescription$/, "")
          (klass_for(type) || klass_for(DEFAULT_TYPE)).new(modality)
        end

        def self.klass_for(type)
          "Renalware::UKRDC::TreatmentTimeline::Generators::#{type}Timeline".safe_constantize
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
renalware-core-2.0.89 app/models/renalware/ukrdc/treatment_timeline/generator_factory.rb
renalware-core-2.0.88 app/models/renalware/ukrdc/treatment_timeline/generator_factory.rb
renalware-core-2.0.87 app/models/renalware/ukrdc/treatment_timeline/generator_factory.rb
renalware-core-2.0.86 app/models/renalware/ukrdc/treatment_timeline/generator_factory.rb
renalware-core-2.0.85 app/models/renalware/ukrdc/treatment_timeline/generator_factory.rb
renalware-core-2.0.84 app/models/renalware/ukrdc/treatment_timeline/generator_factory.rb
renalware-core-2.0.83 app/models/renalware/ukrdc/treatment_timeline/generator_factory.rb
renalware-core-2.0.82 app/models/renalware/ukrdc/treatment_timeline/generator_factory.rb
renalware-core-2.0.81 app/models/renalware/ukrdc/treatment_timeline/generator_factory.rb
renalware-core-2.0.80 app/models/renalware/ukrdc/treatment_timeline/generator_factory.rb