Class: Ruboty::Karma::Actions::List

Inherits:
Actions::Base
  • Object
show all
Defined in:
lib/ruboty/karma/actions/list.rb

Instance Method Summary collapse

Instance Method Details

#argsObject



20
21
22
# File 'lib/ruboty/karma/actions/list.rb', line 20

def args
  message['args'] ? message['args'].split(/\s+/) : []
end

#callObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/ruboty/karma/actions/list.rb', line 5

def call
  key = 'karma-list'
  brain = message.robot.brain
  brain.data[key] ||= []
  lists = brain.data[key].map do |user|
    [user, brain.data["karma-@#{user}"]]
  end
  sorted = lists.sort_by { |e| -e[1] }
  text = sorted.map { |e|
    e[0] = quiet_name(e[0]) if quiet?
    e.join(': ')
  }.join("\n")
  message.reply(text)
end

#quiet?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ruboty/karma/actions/list.rb', line 24

def quiet?
  args.include?('-q') || args.include?('--quiet')
end

#quiet_name(name) ⇒ Object



28
29
30
# File 'lib/ruboty/karma/actions/list.rb', line 28

def quiet_name(name)
  name.split('').join(' ')
end