lita-location-decision 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1663e283614c3cd134b6c2c0be22dea4d588127d
4
+ data.tar.gz: 400a398e0f214c6053ffd87886ca094f1b85207d
5
+ SHA512:
6
+ metadata.gz: dd3041441a55f836e19f4a7a4b436bfe719f516c48f9f87f33154eef2ab526f2e0c37b7d9c229b838951082a22f0382e019034fde9605d3c38b700ea378eef80
7
+ data.tar.gz: 7993f7cad122114ed3ffa87538926b26a751df0fb0463e4511b6bd3d454d5e5ac5d31570c067ebe687fc06d0f04557fa1e36e6169174b336254278b8610e3b91
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ script: bundle exec rake
5
+ before_install:
6
+ - gem update --system
7
+ services:
8
+ - redis-server
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2013 Mitch Dempsey
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # lita-location-decision
2
+
3
+ [![Build Status](https://travis-ci.org/webdestroya/lita-location-decision.png)](https://travis-ci.org/webdestroya/lita-location-decision)
4
+ [![Code Climate](https://codeclimate.com/github/webdestroya/lita-location-decision.png)](https://codeclimate.com/github/webdestroya/lita-location-decision)
5
+ [![Coverage Status](https://coveralls.io/repos/webdestroya/lita-location-decision/badge.png)](https://coveralls.io/r/webdestroya/lita-location-decision)
6
+
7
+ **lita-location-decision** is a handler for [Lita](https://github.com/jimmycuadra/lita) that helps you make a decision about places to go.
8
+
9
+ It is heavily based on the similarly named [hubot plugin](https://github.com/github/hubot-scripts/blob/master/src/scripts/location-decision-maker.coffee).
10
+
11
+ ## Installation
12
+
13
+ Add lita-location-decision to your Lita instance's Gemfile:
14
+
15
+ ``` ruby
16
+ gem "lita-location-decision"
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ``` text
22
+ Lita: remember <location> as a <group> location - Remembers the location for the group
23
+ Lita: forget <location> as a <group> location - Forgets the location from the group
24
+ Lita: forget all locations for <group> - Forgets all the locations for the group
25
+ Lita: forget all <group> locations - Forgets all the locations for the group
26
+ Lita: where can we go for <group>? - Returns a list of places that exist for the group
27
+ Lita: where should we go for <group>? - Returns a randomly selected location for the group
28
+ ```
29
+
30
+ ## License
31
+
32
+ [MIT](http://opensource.org/licenses/MIT)
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,127 @@
1
+ require "lita"
2
+
3
+ module Lita
4
+ module Handlers
5
+
6
+ # Provides a location decision helper
7
+ class LocationDecision < Handler
8
+
9
+ route %r{^remember\s+(.+)\s+as a(?:|n)\s+(.+)\s+location\s*$}i,
10
+ :remember_location, command: true,
11
+ help: {"location-decision" => "For instructions on using the location decision plugin, refer to: https://github.com/webdestroya/lita-location-decision"}
12
+
13
+ route %r{^forget\s+(.+)\s+as a(?:|n)\s+(.+)\s+location\s*$}i,
14
+ :forget_location, command: true
15
+
16
+ route %r{^forget\s+all\s+locations\s+for\s+(.+)\s*$}i,
17
+ :forget_all_locations, command: true
18
+
19
+ route %r{^forget\s+all\s+(.+)\s+locations\s*$}i,
20
+ :forget_all_locations, command: true
21
+
22
+ route %r{^where\s+can\s+(?:.+)\s+go\s+for\s+(.+?)\s*(?:|\?)\s*$}i,
23
+ :list_locations, command: true
24
+
25
+ route %r{^where\s+should\s+(?:.+)\s+go\s+for\s+(.+?)\s*(?:|\?)\s*$}i,
26
+ :choose_location, command: true
27
+
28
+
29
+
30
+ def remember_location(response)
31
+ location = response.matches[0][0]
32
+ group = response.matches[0][1]
33
+
34
+ locations = get_locations(group)
35
+
36
+ locations = [] if locations.nil?
37
+
38
+ locations << location
39
+
40
+ update_locations group, locations
41
+
42
+ response.reply "I have added #{location} to the list of #{group} locations."
43
+ end
44
+
45
+ def forget_location(response)
46
+ location = response.matches[0][0]
47
+ group = response.matches[0][1]
48
+
49
+ locations = get_locations(group)
50
+
51
+ if locations.nil?
52
+ response.reply no_locations(group)
53
+ return
54
+ end
55
+
56
+ locations.reject! {|item| item.downcase.eql?(location.downcase) }
57
+
58
+ update_locations group, locations
59
+
60
+ response.reply "I have removed #{location} from the list of #{group} locations."
61
+ end
62
+
63
+ def forget_all_locations(response)
64
+ group = response.matches[0][0]
65
+
66
+ count = redis.del("location-decision:#{group}")
67
+
68
+ if count == 1
69
+ response.reply "I have removed all #{group} locations."
70
+ else
71
+ response.reply "I do not know about any #{group} locations."
72
+ end
73
+ end
74
+
75
+ def list_locations(response)
76
+ group = response.matches[0][0]
77
+
78
+ locations = get_locations(group)
79
+
80
+ if locations.nil?
81
+ response.reply no_locations(group)
82
+ return
83
+ end
84
+
85
+ response.reply "I know about the following #{group} locations: #{locations.join(', ')}"
86
+ end
87
+
88
+ def choose_location(response)
89
+ group = response.matches[0][0]
90
+
91
+ locations = get_locations(group)
92
+
93
+ if locations.nil?
94
+ response.reply no_locations(group)
95
+ return
96
+ end
97
+
98
+ location = locations.shuffle.first
99
+
100
+ response.reply "I think you should go to #{location} for #{group}."
101
+ end
102
+
103
+ private
104
+
105
+ def no_locations(group)
106
+ "No #{group} locations have been added."
107
+ end
108
+
109
+ def get_locations(group)
110
+ return nil unless redis.exists("location-decision:#{group}")
111
+
112
+ MultiJson.load(redis.get("location-decision:#{group}"))
113
+ end
114
+
115
+ def update_locations(group, locations)
116
+
117
+ # Only compare them by lowercase
118
+ locations.uniq! { |item| item.downcase }
119
+
120
+ redis.set "location-decision:#{group}", MultiJson.dump(locations)
121
+ end
122
+
123
+ end
124
+
125
+ Lita.register_handler(LocationDecision)
126
+ end
127
+ end
@@ -0,0 +1 @@
1
+ require "lita/handlers/location_decision"
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-location-decision"
3
+ spec.version = "0.0.1"
4
+ spec.authors = ["Mitch Dempsey"]
5
+ spec.email = ["mrdempsey@gmail.com"]
6
+ spec.description = %q{A Lita handler for making decisions about places to go}
7
+ spec.summary = %q{A Lita handler for making decisions about places to go}
8
+ spec.homepage = "https://github.com/webdestroya/lita-location-decision"
9
+ spec.license = "MIT"
10
+
11
+ spec.files = `git ls-files`.split($/)
12
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_runtime_dependency "lita", "~> 2.3"
17
+
18
+ spec.add_development_dependency "bundler", "~> 1.3"
19
+ spec.add_development_dependency "rake"
20
+ spec.add_development_dependency "rspec", ">= 2.14"
21
+ spec.add_development_dependency "simplecov"
22
+ spec.add_development_dependency "coveralls"
23
+ end
@@ -0,0 +1,80 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::LocationDecision, lita_handler: true do
4
+ it { routes_command("remember taco bell as a lunch location").to(:remember_location) }
5
+ it { routes_command("forget taco bell as a lunch location").to(:forget_location) }
6
+ it { routes_command("forget all locations for lunch").to(:forget_all_locations) }
7
+ it { routes_command("forget all lunch locations").to(:forget_all_locations) }
8
+
9
+ it { routes_command("where can we go for lunch?").to(:list_locations) }
10
+ it { routes_command("where should we go for lunch?").to(:choose_location) }
11
+
12
+ it { routes_command("where can we go for lunch").to(:list_locations) }
13
+ it { routes_command("where should we go for lunch").to(:choose_location) }
14
+
15
+ # it "checks the parser" do
16
+ # send_command "remember taco bell as a lunch location"
17
+ # expect(replies.last).to_not be_nil
18
+ # expect(replies.last).to eq("No cities match your search query")
19
+ # end
20
+
21
+
22
+ it "checks the system" do
23
+ send_command "remember taco bell as a lunch location"
24
+ expect(replies.last).to_not be_nil
25
+ expect(replies.last).to eq("I have added taco bell to the list of lunch locations.")
26
+
27
+ send_command "where can we go for lunch?"
28
+ expect(replies.last).to_not be_nil
29
+ expect(replies.last).to eq("I know about the following lunch locations: taco bell")
30
+
31
+ send_command "where should we go for lunch?"
32
+ expect(replies.last).to_not be_nil
33
+ expect(replies.last).to eq("I think you should go to taco bell for lunch.")
34
+
35
+ send_command "forget all lunch locations"
36
+ expect(replies.last).to_not be_nil
37
+ expect(replies.last).to eq("I have removed all lunch locations.")
38
+ end
39
+
40
+ it "checks a forget all with no locations" do
41
+ send_command "forget all lunch locations"
42
+ expect(replies.last).to_not be_nil
43
+ expect(replies.last).to eq("I do not know about any lunch locations.")
44
+ end
45
+
46
+ it "checks a forget with no locations" do
47
+ send_command "forget taco bell as a lunch location"
48
+ expect(replies.last).to_not be_nil
49
+ expect(replies.last).to eq("No lunch locations have been added.")
50
+ end
51
+
52
+ it "checks a list with no locations" do
53
+ send_command "where can we go for lunch?"
54
+ expect(replies.last).to_not be_nil
55
+ expect(replies.last).to eq("No lunch locations have been added.")
56
+ end
57
+
58
+ it "checks a choose with no locations" do
59
+ send_command "where should we go for lunch?"
60
+ expect(replies.last).to_not be_nil
61
+ expect(replies.last).to eq("No lunch locations have been added.")
62
+ end
63
+
64
+ it "ensures that locations can be forgotten" do
65
+ send_command "remember taco bell as a lunch location"
66
+ send_command "remember mcdonalds as a lunch location"
67
+
68
+ send_command "where can we go for lunch?"
69
+ expect(replies.last).to_not be_nil
70
+ expect(replies.last).to eq("I know about the following lunch locations: taco bell, mcdonalds")
71
+
72
+ send_command "forget taco bell as a lunch location"
73
+ expect(replies.last).to_not be_nil
74
+ expect(replies.last).to eq("I have removed taco bell from the list of lunch locations.")
75
+
76
+ send_command "where can we go for lunch?"
77
+ expect(replies.last).to_not be_nil
78
+ expect(replies.last).to eq("I know about the following lunch locations: mcdonalds")
79
+ end
80
+ end
@@ -0,0 +1,10 @@
1
+ require "simplecov"
2
+ require "coveralls"
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter
6
+ ]
7
+ SimpleCov.start { add_filter "/spec/" }
8
+
9
+ require "lita-location-decision"
10
+ require "lita/rspec"
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-location-decision
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mitch Dempsey
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '2.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A Lita handler for making decisions about places to go
98
+ email:
99
+ - mrdempsey@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .travis.yml
106
+ - Gemfile
107
+ - LICENSE
108
+ - README.md
109
+ - Rakefile
110
+ - lib/lita-location-decision.rb
111
+ - lib/lita/handlers/location_decision.rb
112
+ - lita-location-decision.gemspec
113
+ - spec/lita/handlers/location_decision_spec.rb
114
+ - spec/spec_helper.rb
115
+ homepage: https://github.com/webdestroya/lita-location-decision
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.0.7
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: A Lita handler for making decisions about places to go
139
+ test_files:
140
+ - spec/lita/handlers/location_decision_spec.rb
141
+ - spec/spec_helper.rb