Sha256: 879a8d7591510794a8f69c093fd5801290dc48a645b91b501c7c34150c1d8571

Contents?: true

Size: 1.06 KB

Versions: 7

Compression:

Stored size: 1.06 KB

Contents

module HQMF1
  
  class Expression
  
    include HQMF1::Utilities
    
    attr_reader :text, :value, :type
  
    def initialize(entry)
      @entry = entry
      @text = @entry.xpath('./*/cda:derivationExpr').text.strip
      type = attr_val('./*/cda:value/@xsi:type')
      case type
      when 'IVL_PQ'
        @value = Range.new(@entry.xpath('./*/cda:value'))
      when 'PQ'
        @value = Value.new(@entry.xpath('./*/cda:value'))
      when 'ANYNonNull'
        @value = HQMF::AnyValue.new
      else
        raise "Unknown expression value type #{type}"
      end
      @type = match_type
    end
    
    def match_type
      case @text
        when /^COUNT(.*)$/
          "COUNT"
        when /^MIN(.*)$/
          "MIN"
        when /^MAX(.*)$/
          "MAX"
        when /^DATEDIFF(.*)$/
          "DATEDIFF"
        else
          raise "unknown expression type: #{@text}"
      end
    end
    
    def to_json
      
      json = build_hash(self, [:text,:type])
      json[:value] = self.value.to_json if self.value
      json
      
    end
    
  end
  
  
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hqmf-parser-1.0.6 lib/hqmf-parser/1.0/expression.rb
hqmf-parser-1.0.5 lib/hqmf-parser/1.0/expression.rb
hqmf-parser-1.0.4 lib/hqmf-parser/1.0/expression.rb
hqmf-parser-1.0.3 lib/hqmf-parser/1.0/expression.rb
hqmf-parser-1.0.2 lib/hqmf-parser/1.0/expression.rb
hqmf-parser-1.0.1 lib/hqmf-parser/1.0/expression.rb
hqmf-parser-1.0.0 lib/hqmf-parser/1.0/expression.rb