Skip to content

Commit

Permalink
Merge pull request #176 from fuzzygroup/master
Browse files Browse the repository at this point in the history
Add template to server as a guide for extending Betty
  • Loading branch information
pickhardt authored Aug 22, 2016
2 parents e1fc356 + 481469b commit 5722907
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/fun.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ def self.interpret(command)
}
end

if command.match(/^superman\s+vs\s+batman$/i)
responses << {
say: [true,false].sample ? "Batman" : "Superman"
}
end

if command.match(/^what\s+if\s+batman\s+does\snot\s+have\s+a?n?y?\s*kryptonite$/i)
responses << {
say: "Batman always has kryptonite"
}
end


if command.match(/^open\s(the\s)?pod\sbay\sdoor(s)?$/i)
responses << {
:say => "I'm sorry, Dave. I'm afraid I can't do that."
Expand Down
24 changes: 24 additions & 0 deletions lib/git.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Git
def self.interpret(command)
responses = []

if command.match(/^undo\s+git\s+add$/i)
responses << {
:say => "To undo a single file use\n\ngit reset filespec\n\n\nTo undo ALL files added (i.e. you want to undo git add .) then use\n\ngit reset"
}
end

responses
end

def self.help
commands = []
commands << {
:category => "Git",
:usage => ["undo git add"]
}
commands
end
end

$executors << Git
67 changes: 67 additions & 0 deletions lib/template.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#
# This file is a template that is designed to give you a starting point for extending Betty
# Copy this file to what you want to extend Betty with. Personally I wrote this as a precursor to
# extending Betty to supporting git development so my first step would be
#
# cp lib/_template.rb lib/git.rb
#

module Template
#
# If you need unit conversions or other meta methods you'd want to locate them here at the top to be consistent with the code base
# See process.rb for examples or convert.rb

#
# You need a self.interpret method which grabs the command and deals with it
#
def self.interpret(command)
responses = []

#
# The guts generally boil down to one or more regular expression matcher against the user's command
#
# Remember to use \s+ as a token delimiter and use () for grouping
#
if command.match(/^$/)
search_term = $1.gsub(' ', '%20')

#
# Build a hash of the possible responses to the user (Note :url is a new idea that I'm floating here)
#
# Your typical options are :command, :say, :explanation
# :command represents the command you want to give the user
# :say is something to be said out loud
# :explanation is what we're teaching the user
# :url is an web url where more details are available
#
# Use Command.browser(url) as a way to open a url
#
responses << {
:command => "",
:explanation => ""
}
end

#
# Return responses
#
responses
end

#
# The help structure
#
def self.help
commands = []
commands << {
:category => "",
:description => '',
:usage => [""]
}
commands
end
end

# this last line is where the magic actually happens; you need to take the executors and assign it to something that does the work
# here it is commented out since this is, well, a template
#$executors << Some Class Goes Here
8 changes: 8 additions & 0 deletions spec/fun_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,13 @@
context 'sudo make me a sandwich' do
it { responds_with say: "I think you meant to place sudo at the start of the command." }
end

context "what if batman does not have any kryptonite" do
it { responds_with say: "Batman always has kryptonite" }
end

context "what if batman does not have kryptonite" do
it { responds_with say: "Batman always has kryptonite" }
end

end
9 changes: 9 additions & 0 deletions spec/git_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'spec_helper'

describe 'Fun' do

context 'undo git add' do
it { responds_with say: "To undo a single file use\n\ngit reset filespec\n\n\nTo undo ALL files added (i.e. you want to undo git add .) then use\n\ngit reset" }
end

end

0 comments on commit 5722907

Please sign in to comment.