<commit_before>class Arista::EAPI::Switch
  attr_accessor :hostname, :user, :password, :protocol, :url, :attributes

  def initialize(hostname, user, password, protocol = 'https')
    self.attributes = {}
    self.hostname = hostname
    self.user = user
    self.password = password
    self.protocol = protocol

    userpass = [ CGI.escape(user), CGI.escape(password) ].join(':')
    self.url = "#{protocol}://#{userpass}@#{hostname}/command-api"
  end

  def interfaces
    run('show interfaces') unless attributes[:interfaces]
    attributes[:interfaces]
  end

  def version
    run('show version') unless attributes[:version]
    attributes[:version]
  end

  def update_attributes!(results)
    results.each { |result| attributes.merge!(result) }
  end

  def run(*commands)
    request = Arista::EAPI::Request.new(self, *commands)
    self.update_attributes!(request.execute.results)
  end
end<commit_msg>Only update attributes if the result is a Hash<commit_after>class Arista::EAPI::Switch
  attr_accessor :hostname, :user, :password, :protocol, :url, :attributes

  def initialize(hostname, user, password, protocol = 'https')
    self.attributes = {}
    self.hostname = hostname
    self.user = user
    self.password = password
    self.protocol = protocol

    userpass = [ CGI.escape(user), CGI.escape(password) ].join(':')
    self.url = "#{protocol}://#{userpass}@#{hostname}/command-api"
  end

  def interfaces
    run('show interfaces')
    attributes[:interfaces]
  end

  def version
    run('show version').first
  end

  def update_attributes!(results)
    results.each { |result| attributes.merge!(result) if result.is_a?(Hash) }
  end

  def run(*commands)
    request = Arista::EAPI::Request.new(self, *commands)
    self.update_attributes!(request.execute.results)
  end
end
{'fraction_non_alphanumeric': 0.1353300055463117, 'fraction_numerical': 0.0, 'mean_word_length': 4.067415730337078, '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': '5492486', 'n_tokens_mistral': 554, 'n_tokens_neox': 550, 'n_words': 126}