Class: Bitmap::Value

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bitmap, value, names) ⇒ Value

Returns a new instance of Value.



17
18
19
20
21
# File 'lib/bitmap.rb', line 17

def initialize (bitmap, value, names)
  @bitmap = bitmap
  @value  = value.to_i
  @names  = names
end

Instance Attribute Details

#bitmapObject (readonly)

Returns the value of attribute bitmap.



15
16
17
# File 'lib/bitmap.rb', line 15

def bitmap
  @bitmap
end

Instance Method Details

#+(*what) ⇒ Object



35
36
37
38
39
# File 'lib/bitmap.rb', line 35

def + (*what)
  bitmap[*(@names + what.flatten.map {|piece|
    piece.to_a rescue piece
  }).flatten.compact]
end

#-(*what) ⇒ Object



41
42
43
44
45
# File 'lib/bitmap.rb', line 41

def - (*what)
  bitmap[*(@names - what.flatten.map {|piece|
    piece.to_a rescue piece
  }).flatten.compact]
end

#has?(mask) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/bitmap.rb', line 23

def has? (mask)
  if mask.is_a?(Value)
    (@names.to_a & mask.to_a) == mask.to_a
  else
    @names.member?(mask.to_s.to_sym)
  end
end

#to_aObject



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

def to_a
  @names
end

#to_iObject



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

def to_i
  @value
end

#to_sObject



51
52
53
# File 'lib/bitmap.rb', line 51

def to_s
  to_a.join '|'
end