Class: Troles::Common::Marshaller::Bitmask

Inherits:
Generic show all
Defined in:
lib/troles/common/marshaller/bitmask.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role_subject) ⇒ Bitmask

Returns a new instance of Bitmask.



8
9
10
# File 'lib/troles/common/marshaller/bitmask.rb', line 8

def initialize role_subject
  super
end

Instance Attribute Details

#role_subjectObject (readonly)

Returns the value of attribute role_subject.



6
7
8
# File 'lib/troles/common/marshaller/bitmask.rb', line 6

def role_subject
  @role_subject
end

#valid_rolesObject (readonly)

Returns the value of attribute valid_roles.



6
7
8
# File 'lib/troles/common/marshaller/bitmask.rb', line 6

def valid_roles
  @valid_roles
end

Instance Method Details

#readObject



12
13
14
15
16
17
# File 'lib/troles/common/marshaller/bitmask.rb', line 12

def read
  valid_roles.reject do |r| 
    num = as_number(ds_field_value) 
    ((num || 0) & calc_index(r)).zero?
  end
end

#write(*roles) ⇒ Object



19
20
21
22
23
# File 'lib/troles/common/marshaller/bitmask.rb', line 19

def write *roles
  roles = roles.uniq.compact
  return as_number(false) if roles.empty?
  roles.to_symbols.map { |r| calc_index(r) }.inject { |sum, bitvalue| sum + bitvalue }          
end