<commit_before>require 'rexml/document'
module ActiveResource
  module Formats
    module AtomFormat
      extend self

      def extension
        "atom"
      end

      def mime_type
        "application/atom+xml"
      end

      def encode(hash, options={})
        hash.to_xml(options)
      end

      def decode(xml)
        if xml =~ /\<atom\:/ 
          xml.gsub!( /\<atom\:/, '<' )
          xml.gsub!( /\<\/atom\:/, '</' )
        end
        return [] if no_content?(xml)
        result = Hash.from_xml(from_atom_data(xml))
        is_collection?(xml) ? result['records'] : result.values.first
      end
      

      private
      
      def from_atom_data(xml)
        if is_collection?(xml)
          result = content_from_collection(xml)
        else
          result = content_from_single_record(xml)
        end
        result.delete('xmlns')
        return result
      end
      
      def no_content?(xml)
        doc = REXML::Document.new(xml)<commit_msg>Only need to do one regex substitution for atom:<commit_after>require 'rexml/document'
module ActiveResource
  module Formats
    module AtomFormat
      extend self

      def extension
        "atom"
      end

      def mime_type
        "application/atom+xml"
      end

      def encode(hash, options={})
        hash.to_xml(options)
      end

      def decode(xml)
        xml.gsub!( /\<(\/?)atom\:/, '<\1' ) # the "events" feeds have "atom:" in front of tags, for some reason
        return [] if no_content?(xml)
        result = Hash.from_xml(from_atom_data(xml))
        is_collection?(xml) ? result['records'] : result.values.first
      end
      

      private
      
      def from_atom_data(xml)
        if is_collection?(xml)
          result = content_from_collection(xml)
        else
          result = content_from_single_record(xml)
        end
        result.delete('xmlns')
        return result
      end
      
      def no_content?(xml)
        doc = REXML::Document.new(xml)
{'fraction_non_alphanumeric': 0.10443995963673057, 'fraction_numerical': 0.0005045408678102926, 'mean_word_length': 1.8532374100719424, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 34}, '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': '2639772', 'n_tokens_mistral': 606, 'n_tokens_neox': 594, 'n_words': 136}