Class: Pyper::Pipes::Cassandra::ModKey
- Inherits:
-
Object
- Object
- Pyper::Pipes::Cassandra::ModKey
- Defined in:
- lib/pyper/pipes/cassandra/mod_key.rb
Overview
Adds the :mod_key field to the output attributes, which is based on the hash of a particular field in the input attributes. If the pipe is configured with an id field of :id, then the input
{ id: 'abc' }
would result in an output of
{ id: 'abc', mod_key: 22 }
Here the value 22 is within the range [0,mod_size - 1] and is uniquely determined by id.
Instance Attribute Summary collapse
-
#id_field ⇒ Object
readonly
Returns the value of attribute id_field.
-
#mod_size ⇒ Object
readonly
Returns the value of attribute mod_size.
Instance Method Summary collapse
-
#initialize(mod_size = 100, id_field = :id) ⇒ ModKey
constructor
A new instance of ModKey.
- #mod(value) ⇒ Object
-
#pipe(attributes, status) ⇒ Hash
The attribute hash with the mod_key field added.
Constructor Details
#initialize(mod_size = 100, id_field = :id) ⇒ ModKey
Returns a new instance of ModKey.
16 17 18 19 |
# File 'lib/pyper/pipes/cassandra/mod_key.rb', line 16 def initialize(mod_size = 100, id_field = :id) @mod_size = mod_size @id_field = id_field end |
Instance Attribute Details
#id_field ⇒ Object (readonly)
Returns the value of attribute id_field.
12 13 14 |
# File 'lib/pyper/pipes/cassandra/mod_key.rb', line 12 def id_field @id_field end |
#mod_size ⇒ Object (readonly)
Returns the value of attribute mod_size.
12 13 14 |
# File 'lib/pyper/pipes/cassandra/mod_key.rb', line 12 def mod_size @mod_size end |
Instance Method Details
#mod(value) ⇒ Object
28 29 30 |
# File 'lib/pyper/pipes/cassandra/mod_key.rb', line 28 def mod(value) Zlib::crc32(value) % mod_size end |
#pipe(attributes, status) ⇒ Hash
Returns The attribute hash with the mod_key field added.
24 25 26 |
# File 'lib/pyper/pipes/cassandra/mod_key.rb', line 24 def pipe(attributes, status) attributes.merge!(:mod_key => mod(attributes[id_field])) end |