module BitwiseAttribute
Constants
- VERSION
Public Class Methods
included(base)
click to toggle source
# File lib/bitwise_attribute.rb, line 12 def self.included(base) base.extend ClassMethods end
Private Instance Methods
value?(mask_column, val)
click to toggle source
Return if value is present in mask (raw value)
# File lib/bitwise_attribute.rb, line 89 def value?(mask_column, val) send(mask_column) & val != 0 end
value_getter(mask_column, mapping)
click to toggle source
Return current value to symbols array
Ex: 16 => [:slots, :credits]
# File lib/bitwise_attribute.rb, line 71 def value_getter(mask_column, mapping) mapping.values.reject { |value| (send(mask_column) & value).zero? }.map do |value| mapping.invert[value] end end
value_setter(mask_column, values, mapping)
click to toggle source
Set current values from values array
# File lib/bitwise_attribute.rb, line 78 def value_setter(mask_column, values, mapping) send("#{mask_column}=", 0) values = values.map(&:to_sym).compact.uniq values &= mapping.keys values.each { |value| send("#{mask_column}=", send(mask_column) | mapping[value]) } end