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.
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
#bitmap ⇒ Object (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
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_a ⇒ Object
31 32 33 |
# File 'lib/bitmap.rb', line 31 def to_a @names end |
#to_i ⇒ Object
47 48 49 |
# File 'lib/bitmap.rb', line 47 def to_i @value end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/bitmap.rb', line 51 def to_s to_a.join '|' end |