Class: Bitmap::Value
- Inherits:
-
Object
- Object
- Bitmap::Value
- Defined in:
- lib/bitmap.rb
Instance Attribute Summary collapse
-
#bitmap ⇒ Object
readonly
Returns the value of attribute bitmap.
Instance Method Summary collapse
- #+(*what) ⇒ Object
- #-(*what) ⇒ Object
- #has?(mask) ⇒ Boolean
-
#initialize(bitmap, value, names) ⇒ Value
constructor
A new instance of Value.
- #to_a ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
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
#bitmap ⇒ Object (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
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_a ⇒ Object
29 30 31 |
# File 'lib/bitmap.rb', line 29 def to_a @names end |
#to_i ⇒ Object
45 46 47 |
# File 'lib/bitmap.rb', line 45 def to_i @value end |
#to_s ⇒ Object
49 50 51 |
# File 'lib/bitmap.rb', line 49 def to_s to_a.join '|' end |