Sha256: c06ad482c185d744aed75b1f08ef95792a6e4fc42a1ea064ab58ce51c52ed2d7

Contents?: true

Size: 561 Bytes

Versions: 3

Compression:

Stored size: 561 Bytes

Contents

class Array

  def to_hashes(test = nil, &block_that_returns_the_records)
    records = block_that_returns_the_records.call
    return [] if records.empty?
    records.map { |record| turn_this_data_into_a_filled_hash(record) }
  end

  private

  def turn_this_data_into_a_filled_hash(record)
    result = {}
    fill_the_hash_with_the_values(result, record)
    result
  end

  def fill_the_hash_with_the_values(result, record)
    self.each_with_index do |field, index|
      value = get_the_value(record, index)
      result[field] = value
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
subtle-1.2.0 lib/subtle/array_to_hashes.rb
subtle-1.1.1 lib/subtle/array_to_hashes.rb
subtle-1.1.0 lib/subtle/array_to_hashes.rb