Class: Lita::Handlers::Remember
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::Remember
- Defined in:
- lib/lita/handlers/remember.rb
Instance Method Summary collapse
- #all_the_terms(response) ⇒ Object
- #fetch_all ⇒ Object
- #fetch_all_terms ⇒ Object
- #forget(response) ⇒ Object
- #lookup(response) ⇒ Object
- #remember(response) ⇒ Object
- #search(response) ⇒ Object
Instance Method Details
#all_the_terms(response) ⇒ Object
87 88 89 |
# File 'lib/lita/handlers/remember.rb', line 87 def all_the_terms(response) response.reply(format_all_the_terms(fetch_all_terms.sort.join("\n - "))) end |
#fetch_all ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/lita/handlers/remember.rb', line 91 def fetch_all() results = {} redis.scan_each(:count => 1000) { |term| definition = redis.hmget(term,'definition')[0] results[term] = definition } return results end |
#fetch_all_terms ⇒ Object
100 101 102 103 104 |
# File 'lib/lita/handlers/remember.rb', line 100 def fetch_all_terms() terms = [] redis.scan_each(:count => 1000) { |term| terms << term } return terms end |
#forget(response) ⇒ Object
55 56 57 58 59 |
# File 'lib/lita/handlers/remember.rb', line 55 def forget(response) term = response.match_data['term'] delete(term) response.reply(format_deletion(term)) end |
#lookup(response) ⇒ Object
49 50 51 52 53 |
# File 'lib/lita/handlers/remember.rb', line 49 def lookup(response) term = response.match_data['term'].chomp('?') return response.reply(t('response.unknown', term: term)) unless known?(term) response.reply(format_definition(term, definition(term))) end |
#remember(response) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/lita/handlers/remember.rb', line 61 def remember(response) term = response.match_data['term'] info = response.match_data['definition'] write(term, info, response.user.id) response.reply(format_confirmation(term, definition(term))) end |
#search(response) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/lita/handlers/remember.rb', line 68 def search(response) type = response.match_data['type'] query = response.match_data['query'] matching_terms = [] if type == 'terms' terms = fetch_all_terms matching_terms = terms.select { |term| term.include?(query) } else fetch_all.each { |term,definition| matching_terms.push(term) if definition.include?(query) } end if matching_terms.empty? response.reply(t('response.empty_search_result', type: type)) else response.reply(format_search(matching_terms.sort.join("\n - "))) end end |