Small gem to manage integer fields as bit vectors of size 32.
Add this line to your application's Gemfile:
gem 'bitvector'
And then execute:
$ bundle
Or install it yourself as:
$ gem install bitvector
You want to represent your data as a bit vector, for example, lets say you want to represent days of the week and store them as a bit vector (assuming days_of_week is an int attribute):
class Schedule < ActiveRecord::Base
serialize days_of_week, BitVector::BitVector
end
schedule = Schedule.new
vector = schedule.days_of_week # => This is a BitVector!
# Mark monday as true
vector[0] = 1
puts vector # => '00000000000000000000000000000001'
If you save a schedule instance, the value will be persisted as integer.
schedule.days_of_week = BitVector::BitVector.new(1).
schedule.save # => days_of_week fields is serialized as 1 in database.
- Fork it ( https://github.com/juanazam/bitvector/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request