Class: Lita::Handlers::OnewheelDoc

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/onewheel_doc.rb

Constant Summary collapse

REDIS_KEY =
'onewheel-doc'

Instance Method Summary collapse

Instance Method Details

#command_add_key(response) ⇒ Object



23
24
25
26
27
28
# File 'lib/lita/handlers/onewheel_doc.rb', line 23

def command_add_key(response)
  key = response.matches[0][0]
  value = response.matches[0][1]
  redis.hset(REDIS_KEY, key, value)
  response.reply "Documented #{key} as #{value}"
end

#command_del_key(response) ⇒ Object



47
48
49
50
51
# File 'lib/lita/handlers/onewheel_doc.rb', line 47

def command_del_key(response)
  key = response.matches[0][0]
  y = redis.hdel(REDIS_KEY, key)
  response.reply "Document deleted: #{key}"
end

#command_fetch_key(response) ⇒ Object



30
31
32
33
34
35
# File 'lib/lita/handlers/onewheel_doc.rb', line 30

def command_fetch_key(response)
  key = response.matches[0][0]

  reply = search_for_key(key)
  response.reply reply
end

#command_list_keys(response) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/lita/handlers/onewheel_doc.rb', line 37

def command_list_keys(response)
  replies = []

  all = redis.hgetall(REDIS_KEY)
  all.each do |key, val|
    replies.push format_key_val_response(key, val)
  end
  response.reply replies.join "\n"
end

#format_key_val_response(all_key, all_val) ⇒ Object



64
65
66
# File 'lib/lita/handlers/onewheel_doc.rb', line 64

def format_key_val_response(all_key, all_val)
  "#{all_key}: #{all_val}"
end

#search_for_key(key) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/lita/handlers/onewheel_doc.rb', line 53

def search_for_key(key)
  values = []
  all = redis.hgetall(REDIS_KEY)
  all.each do |all_key, all_val|
    if all_key =~ /#{key}/
      values.push format_key_val_response(all_key, all_val)
    end
  end
  values.join "\n"
end