Module: HQMF1::Utilities
- Includes:
- HQMF::Conversion::Utilities
- Included in:
- Attribute, Comparison, DataCriteria, Document, Expression, Observation, PopulationCriteria, Precondition, Range, Restriction, Value
- Defined in:
- lib/hqmf-parser/1.0/utilities.rb
Instance Method Summary collapse
-
#attr_val(xpath) ⇒ Object
Utility function to handle optional attributes.
- #clean_json(json) ⇒ Object
- #clean_json_recursive(json) ⇒ Object
Methods included from HQMF::Conversion::Utilities
#build_hash, #check_equality, #json_array, #openstruct_to_json
Instance Method Details
#attr_val(xpath) ⇒ Object
Utility function to handle optional attributes
9 10 11 12 13 14 15 16 |
# 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 |
#clean_json(json) ⇒ Object
18 19 20 |
# 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) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# 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 |