Created
April 6, 2015 18:12
-
-
Save ltk/8bfa829729fb2ddca155 to your computer and use it in GitHub Desktop.
Graba Slack Responder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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