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.



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

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.



13
14
15
# File 'lib/bitmap.rb', line 13

def bitmap
  @bitmap
end

Instance Method Details

#+(*what) ⇒ Object



33
34
35
36
37
# File 'lib/bitmap.rb', line 33

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

#-(*what) ⇒ Object



39
40
41
42
43
# File 'lib/bitmap.rb', line 39

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

#has?(mask) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
# File 'lib/bitmap.rb', line 21

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



29
30
31
# File 'lib/bitmap.rb', line 29

def to_a
  @names
end

#to_iObject



45
46
47
# File 'lib/bitmap.rb', line 45

def to_i
  @value
end

#to_sObject



49
50
51
# File 'lib/bitmap.rb', line 49

def to_s
  to_a.join '|'
end