Skip to content

Commit

Permalink
Heads.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmycuadra committed Aug 30, 2013
0 parents commit c1c41cd
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: ruby
rvm:
- 2.0.0
script: bundle exec rake
before_install:
- gem update --system
notifications:
webhooks:
urls:
- https://lita-freenode.herokuapp.com/travis
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gemspec
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2013 Jimmy Cuadra

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# lita-coin

A handler for [Lita](http://lita.io/) that simply flips a coin and tells you the result.

## Installation

Add lita-coin to your Lita instance's Gemfile:

``` ruby
gem "lita-coin"
```

## Usage

```
[You] Lita: flip a coin
[Lita] Heads!
```

Alternatively, you can say "toss a coin," "coin flip," or "coin toss."

## License

[MIT](http://opensource.org/licenses/MIT)
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
1 change: 1 addition & 0 deletions lib/lita-coin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "lita/handlers/coin"
19 changes: 19 additions & 0 deletions lib/lita/handlers/coin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require "lita"

module Lita
module Handlers
class Coin < Handler
route(/^(?:flip|toss)\s+a\s+coin/i, :flip, command: true, help: {
"flip a coin" => "Flips a coin and tells you the results."
})

route(/^coin\s+(?:toss|flip)/i, :flip, command: true)

def flip(response)
response.reply %w(Heads! Tails!).sample
end
end

Lita.register_handler(Coin)
end
end
23 changes: 23 additions & 0 deletions lita-coin.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Gem::Specification.new do |spec|
spec.name = "lita-coin"
spec.version = "0.0.1"
spec.authors = ["Jimmy Cuadra"]
spec.email = ["[email protected]"]
spec.description = %q{A Lita handler for flipping a coin.}
spec.summary = %q{A Lita handler for flipping a coin.}
spec.homepage = "https://github.com/jimmycuadra/lita-coin"
spec.license = "MIT"

spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_runtime_dependency "lita", "~> 2.3"

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", ">= 2.14"
spec.add_development_dependency "simplecov"
spec.add_development_dependency "coveralls"
end
15 changes: 15 additions & 0 deletions spec/lita/handlers/coin_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "spec_helper"

describe Lita::Handlers::Coin, lita_handler: true do
it { routes_command("flip a coin").to(:flip) }
it { routes_command("toss a coin").to(:flip) }
it { routes_command("coin flip").to(:flip) }
it { routes_command("coin toss").to(:flip) }

describe "#flip" do
it "responds with the results of the flip" do
send_command("flip a coin")
expect(replies.last).to match(/(?:Heads|Tails)!/)
end
end
end
10 changes: 10 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require "simplecov"
require "coveralls"
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
SimpleCov.start { add_filter "/spec/" }

require "lita-coin"
require "lita/rspec"

0 comments on commit c1c41cd

Please sign in to comment.