Class: Lita::Handlers::Coffee

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/moiscot-coffee.rb

Instance Method Summary collapse

Instance Method Details

#coffee(response) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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