Sha256: b456f5da393412c25696a7c75148f2b0a7bd005a8b8a11117059d27c62d21cf4

Contents?: true

Size: 918 Bytes

Versions: 31

Compression:

Stored size: 918 Bytes

Contents

module HQMF1
  module Utilities
    
    include HQMF::Conversion::Utilities
    
    # 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
    def attr_val(xpath)
      attr = @entry.at_xpath(xpath)
      if attr
        attr.value
      else
        nil
      end
    end
    
    def clean_json(json)
      json.reject!{|k,v| v.nil? || (v.respond_to?(:empty?) && v.empty?)}
    end
    
    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
    
  end
end  

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
health-data-standards-3.4.3 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-3.4.2 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-3.4.1 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-3.4.0 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-3.2.12 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-3.3.0 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-3.2.11 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-3.2.10 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-3.2.8 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-3.2.7 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-3.2.6 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-3.2.5 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-3.2.4 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-3.2.3 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-3.2.2 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-3.2.1 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-3.2.0 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-3.1.1 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-3.1.0 lib/hqmf-parser/1.0/utilities.rb
health-data-standards-3.0.6 lib/hqmf-parser/1.0/utilities.rb