Sha256: 5f3eb47217004b3c4b6baf439eb3632043b03fd9978311ff024b9d452f86649d

Contents?: true

Size: 1.5 KB

Versions: 41

Compression:

Stored size: 1.5 KB

Contents

module HQMF1
  # Represents a bound within a HQMF pauseQuantity, has a value, a unit and an
  # inclusive/exclusive indicator
  class Value
    include HQMF1::Utilities
    
    def initialize(entry, inclusive=nil)
      @entry = entry
  
      if (inclusive.nil?)
        case attr_val('./@inclusive')
        when 'true'
          @inclusive = true
        else
          @inclusive = false
        end
      else
        @inclusive = inclusive
      end

    end
    
    def value
      attr_val('./@value')
    end
    
    def unit
      attr_val('./@unit')
    end
    
    def inclusive?
      @inclusive
    end
    
    def to_json
      build_hash(self, [:value,:unit,:inclusive?])
    end
  end
  
  # Represents a HQMF pauseQuantity which can have low and high bounds
  class Range
    include HQMF1::Utilities
    attr_reader :low, :high
    
    def initialize(entry)
      @entry = entry
      if @entry
        @low = optional_value('./cda:low')
        @high = optional_value('./cda:high')
        if (@low == nil && @high == nil)
          @low = optional_value('.',true)
          @high = optional_value('.',true)
        end
      end
    end
   
    def to_json
      json = {}
      json[:low] = self.low.to_json if self.low
      json[:high] = self.high.to_json if self.high
      json
    end
    
    private
    
    def optional_value(xpath, inclusive=nil)
      value_def = @entry.at_xpath(xpath)
      if value_def
        Value.new(value_def, inclusive)
      else
        nil
      end
    end
    
  end
end

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
cqm-parsers-4.1.1.0 lib/hqmf-parser/1.0/range.rb
cqm-parsers-4.1.0.2 lib/hqmf-parser/1.0/range.rb
cqm-parsers-4.1.0.1 lib/hqmf-parser/1.0/range.rb
cqm-parsers-4.1.0.0 lib/hqmf-parser/1.0/range.rb
cqm-parsers-4.0.0.1 lib/hqmf-parser/1.0/range.rb
cqm-parsers-3.2.0.2 lib/hqmf-parser/1.0/range.rb
cqm-parsers-4.0.0.0 lib/hqmf-parser/1.0/range.rb
cqm-parsers-3.2.0.1 lib/hqmf-parser/1.0/range.rb
cqm-parsers-3.2.0.0 lib/hqmf-parser/1.0/range.rb
cqm-parsers-3.1.1.0 lib/hqmf-parser/1.0/range.rb
cqm-parsers-3.1.0.0 lib/hqmf-parser/1.0/range.rb
cqm-parsers-3.0.0.0 lib/hqmf-parser/1.0/range.rb
cqm-parsers-2.0.1 lib/hqmf-parser/1.0/range.rb
cqm-parsers-0.2.4 lib/hqmf-parser/1.0/range.rb
cqm-parsers-2.0.0 lib/hqmf-parser/1.0/range.rb
health-data-standards-4.3.5 lib/hqmf-parser/1.0/range.rb
cqm-parsers-0.2.3 lib/hqmf-parser/1.0/range.rb
health-data-standards-4.3.4 lib/hqmf-parser/1.0/range.rb
cqm-parsers-0.2.2 lib/hqmf-parser/1.0/range.rb
health-data-standards-4.3.3 lib/hqmf-parser/1.0/range.rb