Sha256: 1117a4d755434c47a3ddadb749610e718868d41aae2ac72fe2ac52a3c4ff8d7f

Contents?: true

Size: 1.28 KB

Versions: 75

Compression:

Stored size: 1.28 KB

Contents

module HQMF
  module Conversion
    module Utilities
      def build_hash(source, elements)
        hash = {}
        elements.each do |element|
          value = source.send(element)
          hash[element] = value unless value.nil?
        end
        hash
      end

      def json_array(elements) 
        return nil if elements.nil?
        array = []
        elements.each do |element| 
          if (element.is_a? OpenStruct)
            array << openstruct_to_json(element)
          else
            array << element.to_json 
          end
        end
        array.compact!
        (array.empty?) ? nil : array
      end
      
      def openstruct_to_json(element)
        json = {}
        element.marshal_dump.each do |key,value|
          if value.is_a? OpenStruct
            json[key] = openstruct_to_json(value) 
          elsif (value.class.to_s.split("::").first.start_with? 'HQMF')
            json[key] = value.to_json
          else
            json[key] = value
          end
        end
        json
      end
      
      def check_equality(left,right)
        same = true
        left.instance_variables.each do |variable|
          same &&= left.instance_variable_get(variable) == right.instance_variable_get(variable)
        end
        same
      end
      
    end
  end
end

Version data entries

75 entries across 75 versions & 3 rubygems

Version Path
health-data-standards-3.5.0 lib/hqmf-model/utilities.rb
health-data-standards-3.4.6 lib/hqmf-model/utilities.rb
health-data-standards-3.4.5 lib/hqmf-model/utilities.rb
health-data-standards-3.4.4 lib/hqmf-model/utilities.rb
health-data-standards-3.4.3 lib/hqmf-model/utilities.rb
health-data-standards-3.4.2 lib/hqmf-model/utilities.rb
health-data-standards-3.4.1 lib/hqmf-model/utilities.rb
health-data-standards-3.4.0 lib/hqmf-model/utilities.rb
health-data-standards-3.2.12 lib/hqmf-model/utilities.rb
health-data-standards-3.3.0 lib/hqmf-model/utilities.rb
health-data-standards-3.2.11 lib/hqmf-model/utilities.rb
health-data-standards-3.2.10 lib/hqmf-model/utilities.rb
health-data-standards-3.2.8 lib/hqmf-model/utilities.rb
health-data-standards-3.2.7 lib/hqmf-model/utilities.rb
health-data-standards-3.2.6 lib/hqmf-model/utilities.rb
health-data-standards-3.2.5 lib/hqmf-model/utilities.rb
health-data-standards-3.2.4 lib/hqmf-model/utilities.rb
health-data-standards-3.2.3 lib/hqmf-model/utilities.rb
health-data-standards-3.2.2 lib/hqmf-model/utilities.rb
health-data-standards-3.2.1 lib/hqmf-model/utilities.rb