class Lita::Handlers::Coffee
Public Instance Methods
coffee(response)
click to toggle source
# File lib/lita/handlers/moiscot-coffee.rb, line 12 def coffee(response) # get day from now\ time = Time.new day = time.strftime("%a") # read data json file spec = Gem::Specification.find_by_name("moiscot-coffee") gem_root = spec.gem_dir path = gem_root + '/lib/lita/handlers/data.json' file = File.read(path) data_hash = JSON.parse(file) # compare day with data data_hash.each do |row| if row['day'] == day response.reply "Hoy le toca a #{row['name']} :coffee:" end end rescue => e Lita.logger.error("Coffee#coffee raised #{e.class}: #{e.message}") response.reply "Coffee has turned off the internetz, #{e.class} is raising '#{e.message}'" end