class GitcafeMaid::User

Attributes

bad_words[RW]
good_words[RW]
url[RW]

Public Class Methods

initialize_users() click to toggle source
# File lib/gitcafe_maid/user.rb, line 43
def self.initialize_users
  Dir.glob('users/*.yml').each do |f|
    data = YAML.load File.open(f)
    new_user = User.new data["good_words"],data["bad_words"], data["url"]
    @@users << new_user
  end
end
new(good_words, bad_words, url) click to toggle source
# File lib/gitcafe_maid/user.rb, line 10
def initialize good_words, bad_words, url
  @good_words = good_words.shuffle
  @bad_words  = bad_words.shuffle
  @url = url
end
notify(author, good = true, msg = nil) click to toggle source
# File lib/gitcafe_maid/user.rb, line 51
def self.notify author, good = true, msg = nil
  @@users.sample.notify(author, good, msg)
end

Public Instance Methods

notify(author, good= true, msg=nil) click to toggle source
# File lib/gitcafe_maid/user.rb, line 28
def notify author, good= true, msg=nil
  if msg
    msg = "#{author}: #{msg}"
  else
    msg = (good ? say_good : say_bad)
  end

  if Configuration.im.to_s == "pubu"
    RestClient.post @url, {text: msg}.to_json, :content_type => :json, :accept => :json
  else
    body = {attachments: [color: (good ? "good" : "bad"), text: msg]}
    RestClient.post @url, body.to_json, :content_type => :json, :accept => :json
  end
end
say_bad() click to toggle source
# File lib/gitcafe_maid/user.rb, line 22
def say_bad
  word = @bad_words.pop
  @bad_words.unshift word
  word
end
say_good() click to toggle source
# File lib/gitcafe_maid/user.rb, line 16
def say_good
  word = @good_words.pop
  @good_words.unshift word
  word
end