Class: SmartAleck::CategoryIndexer

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_aleck/category_indexer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(categories) ⇒ CategoryIndexer

Returns a new instance of CategoryIndexer.



11
12
13
14
15
16
17
18
# File 'lib/smart_aleck/category_indexer.rb', line 11

def initialize(categories)
  @category_hash =
    Base58.encode(
      categories.map {|category|
        2 ** (category.respond_to?(:id) ? category.id : category).to_i
      }.inject(:|).to_i
    )
end

Instance Attribute Details

#category_hashObject (readonly)

Returns the value of attribute category_hash.



5
6
7
# File 'lib/smart_aleck/category_indexer.rb', line 5

def category_hash
  @category_hash
end

Class Method Details

.index(categories) ⇒ Object



7
8
9
# File 'lib/smart_aleck/category_indexer.rb', line 7

def self.index(categories)
  new(categories).category_hash
end