Class: Troles::Common::Marshaller::Bitmask
- Defined in:
- lib/troles/common/marshaller/bitmask.rb
Instance Attribute Summary collapse
-
#role_subject ⇒ Object
readonly
Returns the value of attribute role_subject.
-
#valid_roles ⇒ Object
readonly
Returns the value of attribute valid_roles.
Instance Method Summary collapse
-
#initialize(role_subject) ⇒ Bitmask
constructor
A new instance of Bitmask.
- #read ⇒ Object
- #write(*roles) ⇒ Object
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_subject ⇒ Object (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_roles ⇒ Object (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
#read ⇒ Object
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 |