lita-coffee 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f3c2966d0ee2fdcc9072297d548acc55fec26f4
4
- data.tar.gz: c06d43de74adbc4afa51eb4041cfeaf2493466d5
3
+ metadata.gz: 6f20f6086ab2a71bf756506e1964a3f96304a5b2
4
+ data.tar.gz: effaa5303e6209961d13031bf5ed9398297ef28b
5
5
  SHA512:
6
- metadata.gz: af83ca4771b336750659ae91cb24656fbc419102fd7abbb3269132213611251795b9e2db6dbf9f53f08f798fb9496181007db1261b12352194814fb221efb843
7
- data.tar.gz: 5c7f3581c1bd5d8f70c82f7e5a9e8dac12adfd46add2bce7935d53fcbb38c84deacce1a795595225e9e1e35b1250ac5c39b600662eccccbfa6f21d4f1130b2f0
6
+ metadata.gz: 31acb6fa3fafd17a10698d669035fa615a79eb560e7ba4bf0be501f4d5341a4f27a62cd6a8d620e795ef7db1a9dc61d360c00fb5986b750ef655b35ee873cba8
7
+ data.tar.gz: b3c7d86f03856f53e03d56cf051f516eb1e81be511419917e6fc4e67bf72b5cd5f061cfa3ee5b57a3b0bef5ea56092bcfd16f36f8d622f1580bb2a1c2b2c06c7
data/README.md CHANGED
@@ -10,6 +10,8 @@ Add lita-coffee to your Lita instance's Gemfile:
10
10
  gem "lita-coffee"
11
11
  ```
12
12
 
13
+ [![Code Climate](https://codeclimate.com/github/sjauld/lita-coffee/badges/gpa.svg)](https://codeclimate.com/github/sjauld/lita-coffee)
14
+
13
15
  ## Configuration
14
16
 
15
17
  Set the default settings in your lita_config.rb (if you like)
@@ -1,6 +1,6 @@
1
1
  module LitaCoffee
2
2
  # lita-coffee version
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.3'
4
4
  # lita-github version split amongst different revisions
5
5
  MAJOR_VERSION, MINOR_VERSION, REVISION = VERSION.split('.').map(&:to_i)
6
6
  end
@@ -68,18 +68,10 @@ module Lita
68
68
 
69
69
  # Set preferences
70
70
  route(
71
- /^\s*\(?coffee\)?\s+\-s\s+(.*)$/i,
71
+ /^\s*\(?coffee\)?\s+\-([sg])\s+(.*)$/i,
72
72
  :set_prefs,
73
73
  help: {
74
74
  'coffee -s Colombian Filter' => "Set your coffee preference",
75
- }
76
- )
77
-
78
- # Set group
79
- route(
80
- /^\s*\(?coffee\)?\s+\-g\s+(.*)$/i,
81
- :set_group,
82
- help: {
83
75
  'coffee -g Cool Kids' => "Change your group",
84
76
  }
85
77
  )
@@ -179,25 +171,10 @@ module Lita
179
171
  # Set coffee preference
180
172
  # TODO: a single method to update user info
181
173
  def set_prefs(response)
182
- preference = response.matches[0][0].strip rescue nil
183
- result = update_user_coffee(response.user.name,preference)
184
- if result == "OK"
185
- response.reply("Coffee set to #{preference}")
186
- else
187
- response.reply("(sadpanda) Failed to set your coffee for some reason: #{result.inspect}")
188
- end
189
- end
190
-
191
- # Set coffee group
192
- # TODO: merge with coffee preference
193
- def set_group(response)
194
- preference = response.matches[0][0].strip rescue nil
195
- result = set_coffee_group(response.user.name,preference)
196
- if result == "OK"
197
- response.reply("Group set to #{preference}")
198
- else
199
- response.reply("(sadpanda) Failed to set your coffee group for some reason: #{result.inspect}")
200
- end
174
+ mapping = {'g' => :group, 's' => :coffee}
175
+ setting = mapping.detect{|k,v| k == response.matches[0][0]}[1]
176
+ preference = response.matches[0][1].strip rescue nil
177
+ update_preference(response,setting,preference)
201
178
  end
202
179
 
203
180
  # Buy all the coffee for your group
@@ -246,7 +223,21 @@ module Lita
246
223
  def show_stats(response)
247
224
  group = response.matches[0][0].strip rescue get_group(response.user.name)
248
225
  stats = get_coffee_stats(group)
249
- response.reply("Who owes whom?\n--\n#{stats.map{|s| "#{s[0]}: #{s[1]}"}.join("\n")}")
226
+ owing = []
227
+ owed = []
228
+ stats.each do |stat|
229
+ # owing first
230
+ if stat[1] <= 0
231
+ owing << stat
232
+ else
233
+ owed << stat
234
+ end
235
+ end
236
+ owing.sort!{|a,b| a[1] <=> b[1]} # Negative for owing, ergo sort in ascending order
237
+ owed.sort!{|a,b| b[1] <=> a[1]} # Positive for owed, ergo sort in descending order to show who is owed most
238
+ # Provide a response
239
+ response.reply("Coffees owed to others\n--\n#{owing.map{|s| "#{s[0]}: #{s[1]}"}.join("\n")}")
240
+ response.reply("Coffees to be repaid\n--\n#{owed.map{|s| "#{s[0]}: #{s[1]}"}.join("\n")}")
250
241
  end
251
242
 
252
243
  #######
@@ -287,16 +278,15 @@ module Lita
287
278
  JSON.parse(redis.get("settings:#{user}"))['group'] rescue @@DEFAULT_GROUP
288
279
  end
289
280
 
290
- def update_user_coffee(user,coffee)
291
- my_settings = get_settings(user)
292
- my_settings[:coffee] = coffee
293
- redis.set("settings:#{user}",my_settings.to_json)
294
- end
295
-
296
- def set_coffee_group(user,group)
297
- my_settings = get_settings(user)
298
- my_settings[:group] = group
299
- redis.set("settings:#{user}",my_settings.to_json)
281
+ def update_preference(response,setting,preference)
282
+ my_settings = get_settings(response.user.name)
283
+ my_settings[setting] = preference
284
+ result = redis.set("settings:#{response.user.name}",my_settings.to_json)
285
+ if result == "OK"
286
+ response.reply("Updated your #{setting} to #{preference}")
287
+ else
288
+ response.reply("(sadpanda) Failed to update your #{setting} for some reason: #{result.inspect}")
289
+ end
300
290
  end
301
291
 
302
292
  def clear_orders(group)
@@ -22,7 +22,7 @@ describe Lita::Handlers::Coffee, lita_handler: true do
22
22
  it { is_expected.to route('coffee -c').to(:cancel_order)}
23
23
  it { is_expected.to route('coffee -i').to(:display_profile)}
24
24
  it { is_expected.to route('coffee -s Latte').to(:set_prefs)}
25
- it { is_expected.to route('coffee -g Testers').to(:set_group)}
25
+ it { is_expected.to route('coffee -g Testers').to(:set_prefs)}
26
26
  it { is_expected.to route('coffee -b This one is on me :)').to(:buy_coffees)}
27
27
  it { is_expected.to route('coffee -t').to(:system_settings)}
28
28
  it { is_expected.to route('coffee -d').to(:delete_me)}
@@ -60,14 +60,14 @@ describe Lita::Handlers::Coffee, lita_handler: true do
60
60
 
61
61
  it 'sets my coffee preference' do
62
62
  send_message("coffee -s decaf soy cappuccino")
63
- expect(replies.last).to eq("Coffee set to decaf soy cappuccino")
63
+ expect(replies.last).to eq("Updated your coffee to decaf soy cappuccino")
64
64
  send_message("coffee -i")
65
65
  expect(replies.last).to start_with("Your current coffee is decaf soy cappuccino")
66
66
  end
67
67
 
68
68
  it 'changes my coffee group' do
69
69
  set_prefs('stu',{group: 'testing team'})
70
- expect(replies.last).to eq("Group set to testing team")
70
+ expect(replies.last).to eq("Updated your group to testing team")
71
71
  check_prefs('stu')
72
72
  expect(replies.last).to end_with("You are in the testing team group.")
73
73
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-coffee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stuart Auld
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-05 00:00:00.000000000 Z
11
+ date: 2016-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita