<commit_before>require 'json'

module Pyper::WritePipes
  class AttributeSerializer
    def pipe(attributes, status = {})
      attributes.each_with_object({}) do |attr, serialized_attrs|
        value = attr.last
        serialized_attrs[attr.first] = case value
                                       when Array, Hash then JSON.generate(value)
                                       when DateTime then value.to_time
                                       else value
                                       end
      end
    end
  end
end<commit_msg>encode string attributes to utf8<commit_after>require 'json'

module Pyper::WritePipes
  class AttributeSerializer
    def pipe(attributes, status = {})
      attributes.each_with_object({}) do |attr, serialized_attrs|
        value = attr.last
        serialized_attrs[attr.first] = case value
                                       when Array, Hash then JSON.generate(value)
                                       when DateTime then value.to_time
                                       when String then value.dup.force_encoding('UTF-8')
                                       else value
                                       end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.058726220016542596, 'fraction_numerical': 0.0016542597187758478, 'mean_word_length': 1.287334593572779, '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': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5891282', 'n_tokens_mistral': 273, 'n_tokens_neox': 267, 'n_words': 75}