Class: CQM::LogicLibrary

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document
Defined in:
app/models/cqm/logic_library.rb

Overview

CqlElmLibrary encapsulates what used to be a Hash in Ruby, by explicitly specifying a library ID, and the CQL string for that library

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.transform_json(json_hash, target = LogicLibrary.new) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/cqm/logic_library.rb', line 49

def self.transform_json(json_hash, target = LogicLibrary.new)
  result = target
  result['library_name'] = json_hash['library_name'] unless json_hash['library_name'].nil?
  result['library_version'] = json_hash['library_version'] unless json_hash['library_version'].nil?
  result['cql'] = json_hash['cql'] unless json_hash['cql'].nil?
  result['elm'] = json_hash['elm'] unless json_hash['elm'].nil?
  result['elm_annotations'] = json_hash['elm_annotations'] unless json_hash['elm_annotations'].nil?
  result['is_main_library'] = json_hash['is_main_library'] unless json_hash['is_main_library'].nil?
  result['statement_dependencies'] = json_hash['statement_dependencies'].map { |var| CQM::StatementDependency.transform_json(var) } unless json_hash['statement_dependencies'].nil?

  result
end

Instance Method Details

#as_json(*args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/cqm/logic_library.rb', line 22

def as_json(*args)
  result = Hash.new
  unless self.library_name.nil?
    result['library_name'] = self.library_name
  end
  unless self.library_version.nil?
    result['library_version'] = self.library_version
  end
  unless self.cql.nil?
    result['cql'] = self.cql
  end
  unless self.elm.nil?
    result['elm'] = self.elm
  end
  unless self.elm_annotations.nil?
    result['elm_annotations'] = self.elm_annotations
  end
  unless self.is_main_library.nil?
    result['is_main_library'] = self.is_main_library
  end
  unless self.statement_dependencies.nil?  || !self.statement_dependencies.any?
    result['statement_dependencies'] = self.statement_dependencies.map{ |x| x.as_json(*args) }
  end

  result
end