Skip to content

Instantly share code, notes, and snippets.

@ltk

ltk/responder.rb

Created Apr 6, 2015
Embed
What would you like to do?
Graba Slack Responder
class Slack::Responder
def initialize(message)
@message = message
end
def respond?
response.present?
end
def response
@response ||= if room.present?
Slack::RoomMessage.new(room, availability: only_available?, people: people?, book: book?)
elsif office.present?
Slack::OfficeMessage.new(office, availability: only_available?, book: book?)
end
end
private
def office
@office ||= Office.all.detect do |office|
office if office.identifiers.any? do |identifier|
message.match(/#{identifier}/i)
end
end
end
def room
@room ||= Room.all.detect do |room|
room if room.identifiers.any? do |identifier|
message.match(/#{identifier}/i)
end
end
end
def only_available?
message.match(/(free|available|open)/i)
end
def people?
message.match(/who/i)
end
def book?
message.match(/(book|reserve|grab)/i)
end
attr_reader :message
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.