Class: Baku::ComponentMask

Inherits:
Object
  • Object
show all
Defined in:
lib/baku/component_mask.rb

Constant Summary collapse

@@component_set =
Set.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ ComponentMask

Returns a new instance of ComponentMask.



27
28
29
# File 'lib/baku/component_mask.rb', line 27

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/baku/component_mask.rb', line 3

def value
  @value
end

Class Method Details

.from_components(components) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/baku/component_mask.rb', line 14

def from_components(components)
  record_components(components)

  mask_value = 0

  @@component_set.each_with_index do |component, index|
    mask_value |= (1 << index) if components.include?(component)
  end

  ComponentMask.new(mask_value)
end

.record_components(components) ⇒ Object



8
9
10
11
12
# File 'lib/baku/component_mask.rb', line 8

def record_components(components)
  components.each do |component|
    @@component_set << component
  end
end

Instance Method Details

#==(other) ⇒ Object



39
40
41
# File 'lib/baku/component_mask.rb', line 39

def ==(other)
  @value == other.value
end

#add_component(component_class) ⇒ Object



31
32
33
# File 'lib/baku/component_mask.rb', line 31

def add_component(component_class)

end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/baku/component_mask.rb', line 43

def eql?(other)
  self == other
end

#hashObject



47
48
49
# File 'lib/baku/component_mask.rb', line 47

def hash
  value
end

#matches?(other_mask) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/baku/component_mask.rb', line 35

def matches?(other_mask)
  @value & other_mask.value == @value
end