Sha256: 3a5a775042290b92d6cf678a43a1448d75cc9dd7b06fb376710e3bd713337fa3

Contents?: true

Size: 1.62 KB

Versions: 15

Compression:

Stored size: 1.62 KB

Contents

module QDM
  # Represents a Code
  class Code
    attr_accessor :code, :display, :system, :version

    # Code and code system are required (at minimum).
    def initialize(code, sys, display = nil, version = nil)
      @code = code
      @system = sys
      @display = display
      @version = version
    end

    # Converts an object of this instance into a database friendly value.
    def mongoize
      { code: @code, system: @system, display: @display, version: @version, _type: 'QDM::Code' }
    end

    class << self
      # Get the object as it was stored in the database, and instantiate
      # this custom class from it.
      #
      # The array elements in demongoize are the same 5 elements used in mongoize, i.e.
      # [ code, system, display, version ].
      def demongoize(object)
        return nil unless object

        object = object.symbolize_keys
        QDM::Code.new(object[:code], object[:system], object[:display], object[:version])
      end

      # Takes any possible object and converts it to how it would be
      # stored in the database.
      def mongoize(object)
        case object
        when nil then nil
        when QDM::Code then object.mongoize
        when Hash
          object = object.symbolize_keys
          QDM::Code.new(object[:code], object[:system], object[:display], object[:version]).mongoize
        else object
        end
      end

      # Converts the object that was supplied to a criteria and converts it
      # into a database friendly form.
      def evolve(object)
        case object
        when QDM::Code then object.mongoize
        else object
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
cqm-models-4.2.0 app/models/qdm/basetypes/code.rb
cqm-models-3.1.2 app/models/qdm/basetypes/code.rb
cqm-models-4.1.1 app/models/qdm/basetypes/code.rb
cqm-models-4.1.0 app/models/qdm/basetypes/code.rb
cqm-models-4.0.2 app/models/qdm/basetypes/code.rb
cqm-models-4.0.1 app/models/qdm/basetypes/code.rb
cqm-models-4.0.0 app/models/qdm/basetypes/code.rb
cqm-models-3.1.1 app/models/qdm/basetypes/code.rb
cqm-models-3.1.0 app/models/qdm/basetypes/code.rb
cqm-models-3.0.6 app/models/qdm/basetypes/code.rb
cqm-models-3.0.5 app/models/qdm/basetypes/code.rb
cqm-models-3.0.4 app/models/qdm/basetypes/code.rb
cqm-models-3.0.3 app/models/qdm/basetypes/code.rb
cqm-models-3.0.2 app/models/qdm/basetypes/code.rb
cqm-models-3.0.1 app/models/qdm/basetypes/code.rb