<commit_before>require 'xmlsimple'

class Converter
  attr_accessor :jar
  attr_accessor :size_metric
  attr_accessor :color_metric
  attr_accessor :color_adjustment
  attr_accessor :invert_color_metric
  
  def initialize
    @jar = 'jar'
    @size_metric = 'ncloc'
    @color_metric = 'coverage'
    @color_adjustment = 0.0
    @invert_color_metric = false
  end
  
  def convert(input)
    output = ""
    metrics = parse_xml input
    metrics[:resource].each do |resource|
      output << build_output(resource, @jar, @size_metric, @color_metric, @color_adjustment)
    end
    output
  end
  
  def parse_xml(input)
    XmlSimple.xml_in input, { 'GroupTags' => { 'resources' => 'resource' }, 'KeyToSymbol' => true }
  end
  
  def build_output(resource, jar, size, color, adjust)
    name = resource[:name]
    size_metric = find_metric resource[:msr], size
    color_metric = find_metric resource[:msr], color
    color_metric *= -1 unless not @invert_color_metric
    color_metric += adjust
    package = parse_package resource[:key][0]  
    %Q/#{size_metric},#{color_metric},"#{jar}","#{package}","#{name}"\n/  
  end
  
  def find_metric(metrics, key)
    found_metric = 0.0
    metrics.each do |metric|
      if key == metric[:key][0] then
        found_metric = metric[:val][0].to_f
      end
    end
    found_metric
  end
  
  def parse_package(full_name)
    temp = /^.*\./.match full_name
    /^.*[^\.]/.match(temp.to_s)
  end

end<commit_msg>Array was being returned instead of string from XML Simple<commit_after>require 'xmlsimple'

class Converter
  attr_accessor :jar
  attr_accessor :size_metric
  attr_accessor :color_metric
  attr_accessor :color_adjustment
  attr_accessor :invert_color_metric
  
  def initialize
    @jar = 'jar'
    @size_metric = 'ncloc'
    @color_metric = 'coverage'
    @color_adjustment = 0.0
    @invert_color_metric = false
  end
  
  def convert(input)
    output = ""
    metrics = parse_xml input
    metrics[:resource].each do |resource|
      output << build_output(resource, @jar, @size_metric, @color_metric, @color_adjustment)
    end
    output
  end
  
  def parse_xml(input)
    XmlSimple.xml_in input, { 'GroupTags' => { 'resources' => 'resource' }, 'KeyToSymbol' => true }
  end
  
  def build_output(resource, jar, size, color, adjust)
    name = resource[:name][0]
    size_metric = find_metric resource[:msr], size
    color_metric = find_metric resource[:msr], color
    color_metric *= -1 unless not @invert_color_metric
    color_metric += adjust
    package = parse_package resource[:key][0]  
    %Q/#{size_metric},#{color_metric},"#{jar}","#{package}","#{name}"\n/  
  end
  
  def find_metric(metrics, key)
    found_metric = 0.0
    metrics.each do |metric|
      if key == metric[:key][0] then
        found_metric = metric[:val][0].to_f
      end
    end
    found_metric
  end
  
  def parse_package(full_name)
    temp = /^.*\./.match full_name
    /^.*[^\.]/.match(temp.to_s)
  end

end
{'fraction_non_alphanumeric': 0.12339851652056642, 'fraction_numerical': 0.0057316250842886045, 'mean_word_length': 3.337719298245614, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '6096020', 'n_tokens_mistral': 1020, 'n_tokens_neox': 1021, 'n_words': 226}