Class: River::UniqueBitmask
- Inherits:
-
Object
- Object
- River::UniqueBitmask
- Defined in:
- lib/unique_bitmask.rb
Class Method Summary collapse
Class Method Details
.from_states(states) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/unique_bitmask.rb', line 15 def self.from_states(states) val = 0 states.each do |state| bit_index = JOB_STATE_BIT_POSITIONS[state] bit_position = 7 - (bit_index % 8) val |= 1 << bit_position end format("%08b", val) end |
.to_states(mask) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/unique_bitmask.rb', line 28 def self.to_states(mask) states = [] #: Array[jobStateAll] # rubocop:disable Layout/LeadingCommentSpace JOB_STATE_BIT_POSITIONS.each do |state, bit_index| bit_position = 7 - (bit_index % 8) if (mask & (1 << bit_position)) != 0 states << state end end states.sort end |