Sha256: b8e09c5db777a6a77cae73e739959555f26aad06376d76ce12e5cb4995d12266

Contents?: true

Size: 1.52 KB

Versions: 2

Compression:

Stored size: 1.52 KB

Contents

# MultidimensionalTable

This is a product of a coding kata. I wanted an easy way to describe multidimensional table
but only using ruby code and not some sort of .yaml or other custom format that you have to parse in some way.

For example:

```
1994      
  BuenosAires
    Coal
      19t
    Potassium
      5t
1995 
  BuenosAires
    Coal  
      8t
    Potassium
      6t
```

Then if I say I need to get Coal in Buenos Aires in 1995 I wan't to get 8t. The idea is to make easy DSL to 
describe the same thing in pure Ruby.

## Installation

Add this line to your application's Gemfile:

    gem 'multidimensional_table'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install multidimensional_table

## Usage

```
class MaterialConsumption
  include MultidimensionalTable

  dimensions  :year => [:year_1994, :year_1995],
              :city => [:buenos_aires],
              :material => [:coal, :potassium]

  table_data do
    year_1994 do
      buenos_aires do
        coal '8t' 
        potassium '5t' 
      end
    end

    year_1995 do
      buenos_aires do
        coal '8t' 
        potassium '6t' 
      end
    end
  end

end

mt = new MaterialConsumption
mt.update_attributes(:year => :year_1994, :city => :buenos_aires, :material => :coal)
mt.table_result #=> '8t'
```

## Contributing

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
multidimensional_table-1.0.1 README.md
multidimensional_table-1.0.0 README.md