Project

arr2hash

0.0
No release in over a year
The arr2hash gem provides a simple way to convert a 2D array into an array of hashes. The first row of the 2D array is used as the keys, and the subsequent rows are converted to values, creating an array of hashes. This is especially useful for converting structured data like CSV.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 2.0
~> 10.0
~> 3.0
 Project Readme

Arr2hash

This README and the corresponding gem were created with the help of ChatGPT by OpenAI.

Overview

arr2hash is a Ruby gem that provides a simple way to convert a two-dimensional array into an array of hashes. The first sub-array is treated as the keys, and the subsequent sub-arrays are treated as the values.

Installation

Add this line to your application's Gemfile:

gem 'arr2hash'

And then execute;

bundle install

Or install it yourself as:

gem install arr2hash

Usage

Using arr2hash is straightforward. Simply call the a_to_hash method on a two-dimensional array as shown below:

require "arr2hash"

array = [
  ["title", "content", "user_name"],
  ["A", "a", "あ"],
  ["B", "b", "い"]
]

result = Arr2hash.a_to_hash(array)

The result will be:

[
  {title: "A", content: "a", user_name: "あ"},
  {title: "B", content: "b", user_name: "い"}
]

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/zio-tt/arr2hash.