Class: Cuboid::Support::Filter::Base Abstract
- Defined in:
- lib/cuboid/support/filter/base.rb
Overview
This class is abstract.
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_OPTIONS =
{ hasher: :hash }
Instance Attribute Summary collapse
-
#collection ⇒ Object
Returns the value of attribute collection.
Class Method Summary collapse
Instance Method Summary collapse
-
#<<(item) ⇒ Base
‘self`.
- #==(other) ⇒ Object
- #_dump(_) ⇒ Object
- #any? ⇒ Boolean
- #clear ⇒ Object
- #dup ⇒ Object
- #empty? ⇒ Boolean
- #hash ⇒ Object
- #include?(item) ⇒ Bool
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #merge(other) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
17 18 19 20 |
# File 'lib/cuboid/support/filter/base.rb', line 17 def initialize( = {} ) @options = DEFAULT_OPTIONS.merge( ) @hasher = @options[:hasher].to_sym end |
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
8 9 10 |
# File 'lib/cuboid/support/filter/base.rb', line 8 def collection @collection end |
Class Method Details
._load(data) ⇒ Object
93 94 95 |
# File 'lib/cuboid/support/filter/base.rb', line 93 def self._load( data ) from_rpc_data Marshal.load( data ) end |
Instance Method Details
#<<(item) ⇒ Base
Returns ‘self`.
27 28 29 30 |
# File 'lib/cuboid/support/filter/base.rb', line 27 def <<( item ) @collection << calculate_hash( item ) self end |
#==(other) ⇒ Object
77 78 79 |
# File 'lib/cuboid/support/filter/base.rb', line 77 def ==( other ) hash == other.hash end |
#_dump(_) ⇒ Object
89 90 91 |
# File 'lib/cuboid/support/filter/base.rb', line 89 def _dump( _ ) Marshal.dump( to_rpc_data ) end |
#any? ⇒ Boolean
44 45 46 |
# File 'lib/cuboid/support/filter/base.rb', line 44 def any? !empty? end |
#clear ⇒ Object
52 53 54 |
# File 'lib/cuboid/support/filter/base.rb', line 52 def clear @collection.clear end |
#dup ⇒ Object
85 86 87 |
# File 'lib/cuboid/support/filter/base.rb', line 85 def dup self.class.new( @options.dup ).merge self end |
#empty? ⇒ Boolean
40 41 42 |
# File 'lib/cuboid/support/filter/base.rb', line 40 def empty? @collection.empty? end |
#hash ⇒ Object
81 82 83 |
# File 'lib/cuboid/support/filter/base.rb', line 81 def hash @collection.hash end |
#include?(item) ⇒ Bool
36 37 38 |
# File 'lib/cuboid/support/filter/base.rb', line 36 def include?( item ) @collection.include? calculate_hash( item ) end |
#merge(other) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/cuboid/support/filter/base.rb', line 56 def merge( other ) case other when self.class @collection.merge other.collection when Array other.each do |k| fail 'Cannot merge with unhashed entries' if !k.is_a?( Numeric ) @collection << k end else fail ArgumentError, "Don't know how to merge with: #{other.class}" end self end |
#size ⇒ Object
48 49 50 |
# File 'lib/cuboid/support/filter/base.rb', line 48 def size @collection.size end |