<commit_before>class Vertica::Result
  include Enumerable
  
  attr_reader :columns
  attr_reader :rows
  attr_accessor :tag, :notice

  def initialize(row_style = :hash)
    @row_style = row_style
    @rows = []
  end

  def descriptions=(message)
    @columns = message.fields.map { |fd| Vertica::Column.new(fd) }
  end

  def format_row_as_hash(row_data)
    row = {}
    row_data.values.each_with_index do |value, idx|
      col = columns[idx]
      row[col.name] = col.convert(value)
    end
    row
  end
  
  def format_row(row_data)
    send("format_row_as_#{@row_style}", row_data)
  end
  
  def format_row_as_array(row_data)
    row = []
    row_data.values.each_with_index do |value, idx|
      row << columns[idx].convert(value)
    end
    row
  end

  def add_row(row)
    @rows << row
  end

  def each_row(&block)
    @rows.each(&block)
  end
  
  def empty?
    @rows.empty?
  end
  
  def the_value
    if empty?
      nil
    else
      @row_style == :array ? rows[0][0] : rows[0][columns[0].name]
    end
  end
  
  alias_method :each, :each_row

  def row_count
    @rows.size
  end

  alias_method :size, :row_count
  alias_method :length, :row_count
end<commit_msg>Add a simple result set accessor method.<commit_after>class Vertica::Result
  include Enumerable
  
  attr_reader :columns
  attr_reader :rows
  attr_accessor :tag, :notice

  def initialize(row_style = :hash)
    @row_style = row_style
    @rows = []
  end

  def descriptions=(message)
    @columns = message.fields.map { |fd| Vertica::Column.new(fd) }
  end

  def format_row_as_hash(row_data)
    row = {}
    row_data.values.each_with_index do |value, idx|
      col = columns[idx]
      row[col.name] = col.convert(value)
    end
    row
  end
  
  def format_row(row_data)
    send("format_row_as_#{@row_style}", row_data)
  end
  
  def format_row_as_array(row_data)
    row = []
    row_data.values.each_with_index do |value, idx|
      row << columns[idx].convert(value)
    end
    row
  end

  def add_row(row)
    @rows << row
  end

  def each_row(&block)
    @rows.each(&block)
  end
  
  def empty?
    @rows.empty?
  end
  
  def the_value
    if empty?
      nil
    else
      @row_style == :array ? rows[0][0] : rows[0][columns[0].name]
    end
  end

  def [](row, col = nil)
    col.nil? ? row[row] : rows[row][col]
  end
  
  alias_method :each, :each_row

  def row_count
    @rows.size
  end

  alias_method :size, :row_count
  alias_method :length, :row_count
end
{'fraction_non_alphanumeric': 0.11178369652945924, 'fraction_numerical': 0.003228410008071025, 'mean_word_length': 2.8079877112135176, 'pattern_counts': {'":': 0, '<': 11, '<?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': '7181931', 'n_tokens_mistral': 941, 'n_tokens_neox': 925, 'n_words': 203}