<commit_before>module BioVcf

  class VcfRecordInfo 
    def initialize s
      @h = {}
      @original_key = {}
      s.split(/;/).each do |f| 
        k,v = f.split(/=/) 
        # self[k] = v 
        kupper = k.upcase
        @h[kupper] = v
        @original_key[kupper] = k
      end
    end

    def to_s
      @h.map { |k,v| (v ? @original_key[k] + '=' + v : @original_key[k])  }.join(';')
    end

    # Set INFO fields (used by --rewrite)
    def []= k, v   
      kupper = k.upcase
      @h[kupper] = v
      @original_key[kupper] = k
    end

    def method_missing(m, *args, &block) 
      v = @h[m.to_s.upcase]
      ConvertStringToValue::convert(v)
    end  
  end

  module VcfRecordParser
    # Parse the format field into a Hash
    def VcfRecordParser.get_format s
      h = {}
      s.split(/:/).each_with_index { |v,i| h[v] = i }
      h
    end
    def VcfRecordParser.get_info s
      VcfRecordInfo.new(s)
    end<commit_msg>Postpone info record splitting<commit_after>module BioVcf

  class VcfRecordInfo 
    def initialize s
      @info = s
    end

    def to_s
      if @h
        @h.map { |k,v| (v ? @original_key[k] + '=' + v : @original_key[k])  }.join(';')
      else
        @info
      end
    end

    # Set INFO fields (used by --rewrite)
    def []= k, v   
      split_fields
      kupper = k.upcase
      @h[kupper] = v
      @original_key[kupper] = k
    end

    def method_missing(m, *args, &block)
      split_fields if not @h
      v = @h[m.to_s.upcase]
      ConvertStringToValue::convert(v)
    end  

  private
 
    def split_fields
      @h = {}
      @original_key = {}
      @info.split(/;/).each do |f| 
        k,v = f.split(/=/) 
        # self[k] = v 
        kupper = k.upcase
        @h[kupper] = v
        @original_key[kupper] = k
      end
    end
  end

  module VcfRecordParser
    # Parse the format field into a Hash
    def VcfRecordParser.get_format s
      h = {}
      s.split(/:/).each_with_index { |v,i| h[v] = i }
      h
    end
    def VcfRecordParser.get_info s
      VcfRecordInfo.new(s)
    end
{'fraction_non_alphanumeric': 0.12759787336877718, 'fraction_numerical': 0.0, 'mean_word_length': 1.7710843373493976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3481278', 'n_tokens_mistral': 792, 'n_tokens_neox': 764, 'n_words': 184}