Class: Soulheart::Base

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/soulheart/base.rb

Direct Known Subclasses

Loader, Matcher

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#normalize, #prefixes_for_phrase

Instance Attribute Details

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/soulheart/base.rb', line 5

def type
  @type
end

Instance Method Details

#base_idObject



15
16
17
# File 'lib/soulheart/base.rb', line 15

def base_id
  ENV['RACK_ENV'] != 'test' ? 'soulheart:' : 'soulheart_test:'
end

#cache_durationObject



11
12
13
# File 'lib/soulheart/base.rb', line 11

def cache_duration
  10 * 60 # Setting to 10 minutes, but making it possible to edit down the line
end

#cache_id(type = 'all') ⇒ Object



61
62
63
# File 'lib/soulheart/base.rb', line 61

def cache_id(type = 'all')
  "#{base_id}cache:#{type}:"
end

#categories_idObject



45
46
47
# File 'lib/soulheart/base.rb', line 45

def categories_id
  "#{base_id}categories:"
end

#category_combosObject



41
42
43
# File 'lib/soulheart/base.rb', line 41

def category_combos
  redis.smembers(category_combos_id)
end

#category_combos_idObject



37
38
39
# File 'lib/soulheart/base.rb', line 37

def category_combos_id
  "#{base_id}category_combos:"
end

#category_id(name = 'all') ⇒ Object



49
50
51
# File 'lib/soulheart/base.rb', line 49

def category_id(name = 'all')
  "#{categories_id}#{name}:"
end

#combinatored_category_arrayObject



23
24
25
26
27
# File 'lib/soulheart/base.rb', line 23

def combinatored_category_array
  1.upto(sorted_category_array.size).
    flat_map { |n| sorted_category_array.combination(n).
    map { |el| el.join('') } }
end

#no_query_id(category = category_id) ⇒ Object



53
54
55
# File 'lib/soulheart/base.rb', line 53

def no_query_id(category = category_id)
  "all:#{category}"
end

#redisObject



7
8
9
# File 'lib/soulheart/base.rb', line 7

def redis
  Soulheart.redis
end

#results_hashes_idObject



57
58
59
# File 'lib/soulheart/base.rb', line 57

def results_hashes_id
  "#{base_id}database:"
end

#set_category_combos_arrayObject



29
30
31
32
33
34
35
# File 'lib/soulheart/base.rb', line 29

def set_category_combos_array
  redis.expire category_combos_id, 0
  array = combinatored_category_array
  array.last.replace('all')
  redis.sadd category_combos_id, array
  array
end

#sorted_category_arrayObject



19
20
21
# File 'lib/soulheart/base.rb', line 19

def sorted_category_array
  redis.smembers(categories_id).map { |c| normalize(c) }.uniq.sort
end