Sha256: 89bde7d3ffa797dd922b720e8d6967a9ec73a84cbaad7dce541b9c63b683b97f

Contents?: true

Size: 1.61 KB

Versions: 2

Compression:

Stored size: 1.61 KB

Contents

# Enumeration

Add enumerated value attributes to your ruby classes.

## Usage

```ruby
require 'enumeration'

class Thing
  include Enumeration

  # list enumeration
  enum :word, %w{aye bee see}

  # map enumeration
  enum :stuff, {
    :a => "aye",
    :b => "bee",
    :c => "see"
  }
end

# get the enum sets
Thing.word_set      # => ['aye', 'bee', 'see']
Thing.stuff_set     # => [:a, :b, :c]

# lookup mapped enum values
Thing.stuff(:a)     # => "aye"


t = Thing.new

# write list enum values
t.word              # => nil
t.word = "aye"
t.word              # => "aye"
t.word_key          # => "aye" (a list's 'keys' are it's values, vice-versa)
t.word = "dee"
t.word              # => nil  (won't write non enum values)
t.word_key          # => nil

# write mapped enum value
t.stuff             # => nil
t.stuff = :b        #    (write using key)
t.stuff             # => "bee"
t.stuff_key         # => :b
t.stuff = "see"     #    (write using value)
t.stuff             # => "see"
t.stuff_key         # => :c
t.stuff = :d
t.stuff             # => nil (won't write non enum keys)
t.stuff_key         # => nil
t.stuff = "dee"
t.stuff             # => nil (won't write non enum values)
t.stuff_key         # => nil
```

## Installation

Add this line to your application's Gemfile:

    gem 'enumeration'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install enumeration

## 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
enumeration-1.3.3 README.md
enumeration-1.3.2 README.md