<commit_before>require 'rubygems'
require 'rest_client'
require 'nokogiri'
require 'builder'

module Pivotal
  class Base
    include Pivotal::Associations
    
    attr_accessor :resource, :xml
    undef id
    
    def initialize(params = {})
      params.each do |key, value|
        send("#{key}=", value)
      end
    end    
    
    def xml
      @xml ||= resource.get
    end

    def parsed_resource
      @parsed_resource ||= Nokogiri::XML(xml)
    end
    
    def method_missing(method, *args)
      parsed_resource.css(method.to_s).text
    end
    
    def update_attributes(options = {})
      @xml = resource.put generate_xml(options)
    end
    
    class << self
      def xpath
        '//' + self.name.gsub(/.+\:\:/, '').downcase
      end
    end
    
  private
  
    def generate_xml(options = {})
      builder = Builder::XmlMarkup.new
      allowed_keys(options).each do |key, value|
        builder.key(value.to_s)
      end
      
      builder
    end
    
    def allowed_keys(options = {})
      options.reject do |key, _|
        !%w[id story_type url estimate current_state
           description name requested_by owned_by
           created_at accepted_at labels].include? key.to_s
      end
    end
    
  end
end<commit_msg>Pulling Pivotal::Base.name_as_xml_attribute out of .xpath<commit_after>require 'rubygems'
require 'rest_client'
require 'nokogiri'
require 'builder'

module Pivotal
  class Base
    include Pivotal::Associations
    
    attr_accessor :resource, :xml
    undef id
    
    def initialize(params = {})
      params.each do |key, value|
        send("#{key}=", value)
      end
    end    
    
    def xml
      @xml ||= resource.get
    end

    def parsed_resource
      @parsed_resource ||= Nokogiri::XML(xml)
    end
    
    def method_missing(method, *args)
      parsed_resource.css(method.to_s).text
    end
    
    def update_attributes(options = {})
      @xml = resource.put generate_xml(options)
    end
    
    class << self
      def name_as_xml_attribute
        self.name.gsub(/.+\:\:/, '').downcase
      end
      
      def xpath
        '//' + self.name_as_xml_attribute
      end
    end
    
  private
  
    def generate_xml(options = {})
      builder = Builder::XmlMarkup.new
      allowed_keys(options).each do |key, value|
        builder.key(value.to_s)
      end
      
      builder
    end
    
    def allowed_keys(options = {})
      options.reject do |key, _|
        !%w[id story_type url estimate current_state
           description name requested_by owned_by
           created_at accepted_at labels].include? key.to_s
      end
    end
    
  end
end
{'fraction_non_alphanumeric': 0.0953996983408748, 'fraction_numerical': 0.0, 'mean_word_length': 2.074159907300116, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 17}, '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': '3994504', 'n_tokens_mistral': 845, 'n_tokens_neox': 853, 'n_words': 193}