Class: QDM::Code

Inherits:
Object
  • Object
show all
Defined in:
app/models/qdm/basetypes/code.rb

Overview

Represents a Code

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, sys, display = nil, version = nil) ⇒ Code

Code and code system are required (at minimum).



7
8
9
10
11
12
# File 'app/models/qdm/basetypes/code.rb', line 7

def initialize(code, sys, display = nil, version = nil)
  @code = code
  @system = sys
  @display = display
  @version = version
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



4
5
6
# File 'app/models/qdm/basetypes/code.rb', line 4

def code
  @code
end

#displayObject

Returns the value of attribute display.



4
5
6
# File 'app/models/qdm/basetypes/code.rb', line 4

def display
  @display
end

#systemObject

Returns the value of attribute system.



4
5
6
# File 'app/models/qdm/basetypes/code.rb', line 4

def system
  @system
end

#versionObject

Returns the value of attribute version.



4
5
6
# File 'app/models/qdm/basetypes/code.rb', line 4

def version
  @version
end

Class Method Details

.demongoize(object) ⇒ Object

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 ].



25
26
27
28
29
30
# File 'app/models/qdm/basetypes/code.rb', line 25

def demongoize(object)
  return nil unless object

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

.evolve(object) ⇒ Object

Converts the object that was supplied to a criteria and converts it into a database friendly form.



47
48
49
50
51
52
# File 'app/models/qdm/basetypes/code.rb', line 47

def evolve(object)
  case object
  when QDM::Code then object.mongoize
  else object
  end
end

.mongoize(object) ⇒ Object

Takes any possible object and converts it to how it would be stored in the database.



34
35
36
37
38
39
40
41
42
43
# File 'app/models/qdm/basetypes/code.rb', line 34

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

Instance Method Details

#mongoizeObject

Converts an object of this instance into a database friendly value.



15
16
17
# File 'app/models/qdm/basetypes/code.rb', line 15

def mongoize
  { code: @code, system: @system, display: @display, version: @version, _type: 'QDM::Code' }
end