module HQMF1::Utilities
Public Instance Methods
attr_val(xpath)
click to toggle source
Utility function to handle optional attributes @param xpath an XPath that identifies an XML attribute @return the value of the attribute or nil if the attribute is missing
# File lib/hqmf-parser/1.0/utilities.rb, line 9 def attr_val(xpath) attr = @entry.at_xpath(xpath) if attr attr.value else nil end end
check_nil_conjunction_on_child()
click to toggle source
Preconditions can have nil conjunctions as part of a DATEDIFF, we want to remove these and warn
# File lib/hqmf-parser/1.0/utilities.rb, line 41 def check_nil_conjunction_on_child if (@preconditions.length == 1 && @preconditions.first.conjunction.nil?) bad_precondition = @preconditions.first if (bad_precondition.restrictions.empty? && bad_precondition.subset.nil? && bad_precondition.expression.nil?) @preconditions = @preconditions.first.preconditions #puts "\t FIXED PRECONDITION WITHOUT CONJUNCTION" else puts "\t PRECONDITION WITHOUT CONJUNCTION: Cannot be fixed" end end end
clean_json(json)
click to toggle source
# File lib/hqmf-parser/1.0/utilities.rb, line 18 def clean_json(json) json.reject!{|k,v| v.nil? || (v.respond_to?(:empty?) && v.empty?)} end
clean_json_recursive(json)
click to toggle source
# File lib/hqmf-parser/1.0/utilities.rb, line 22 def clean_json_recursive(json) json.each do |k,v| if v.is_a? Hash clean_json_recursive(v) clean_json(v) elsif v.is_a? Array v.each do |e| if e.is_a? Hash clean_json_recursive(e) clean_json(e) end end end end clean_json(json) end