module HQMF::Conversion::Utilities
Public Instance Methods
build_hash(source, elements)
click to toggle source
# File lib/hqmf-model/utilities.rb, line 5 def build_hash(source, elements) hash = {} elements.each do |element| value = source.send(element) hash[element] = value unless value.nil? end hash end
check_equality(left,right)
click to toggle source
# File lib/hqmf-model/utilities.rb, line 42 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
json_array(elements)
click to toggle source
# File lib/hqmf-model/utilities.rb, line 14 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
openstruct_to_json(element)
click to toggle source
# File lib/hqmf-model/utilities.rb, line 28 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