lita-onewheel-snowcrash 0.0.0 → 1.0.0

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: 708c538034b9fddc20adb3722b92a0476b59c711
4
- data.tar.gz: 5cef73da0427fb12bdf221328693ee4505304f7d
3
+ metadata.gz: a843e12d5988db8f669474e9472c046551e1c76f
4
+ data.tar.gz: df8d276c7f63dd53136f5fea406f236b2823bb84
5
5
  SHA512:
6
- metadata.gz: 8ceaabae79b5d64d043f5df7450b198e6d5fe5da0429654433e7161b365a7615bcdc62110e2fd05fdfebeed0bbe6c998c7c9045af64607e7251eb47513d2314c
7
- data.tar.gz: 64f7785ebf008d5a02d4bda64a7a830d57cd32f5c5bd5518e4755abbfaa6afaf18b1ff6a99097ff3632abb5552da274adb04206f42f3ac70afc59475c0f39538
6
+ metadata.gz: 7b90cc30865e5d92ee5d8ecc497da8c4296efac515b19305c36bfcda8385139675fd7edce01ec12704949a110be4a45dc17edad28d91e38ab2b7110541393396
7
+ data.tar.gz: 79dbfc7669e78f15f8700d6ce18f416cf902f16c4014c800d45cfd0e8cb0b3616346fb97e768ef40b796bb9c213c8f6687ce29aca3bb5ae6cf71adeb324fb5c7
@@ -4,26 +4,50 @@ module Lita
4
4
  module Handlers
5
5
  class OnewheelSnowcrash < Handler
6
6
  route /^snowcrash$/i,
7
- :generate_random,
7
+ :generate_random_sentence,
8
8
  command: true
9
9
  route /^snowcrash (\d+)$/i,
10
10
  :generate_by_number,
11
11
  command: true
12
+ route /^snowcrashwords$/i,
13
+ :generate_random_words,
14
+ command: true
15
+ route /^snowcrashwords (\d+)$/i,
16
+ :generate_words_by_number,
17
+ command: true
12
18
 
13
- def generate_random(response)
14
- response.reply return_chain(Random::rand(20))
19
+ def generate_random_sentence(response)
20
+ response.reply return_sentence_chain(1)
15
21
  end
16
22
 
17
23
  def generate_by_number(response)
18
- response.reply return_chain(response.matches[0][0])
24
+ response.reply return_sentence_chain(response.matches[0][0])
25
+ end
26
+
27
+ def generate_random_words(response)
28
+ response.reply return_word_chain(Random::rand(20))
29
+ end
30
+
31
+ def generate_words_by_number(response)
32
+ response.reply return_word_chain(response.matches[0][0])
33
+ end
34
+
35
+ def get_markov
36
+ MarkyMarkov::Dictionary.new('dict/snowcrash')
19
37
  end
20
38
 
21
- def return_chain(number)
22
- puts "Generating #{number} words."
23
- markov = MarkyMarkov::Dictionary.new('dict/snowcrash') # Saves/opens dictionary.mmd
39
+ def return_word_chain(number)
40
+ Lita.logger.info "Generating #{number} words."
41
+ markov = get_markov # Saves/opens dictionary.mmd
24
42
  markov.generate_n_words(number.to_i)
25
43
  end
26
44
 
45
+ def return_sentence_chain(number)
46
+ Lita.logger.info "Generating #{number} sentences."
47
+ markov = get_markov # Saves/opens dictionary.mmd
48
+ markov.generate_n_sentences(number.to_i)
49
+ end
50
+
27
51
  Lita.register_handler(self)
28
52
  end
29
53
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-onewheel-snowcrash'
3
- spec.version = '0.0.0'
3
+ spec.version = '1.0.0'
4
4
  spec.authors = ['Andrew Kreps']
5
5
  spec.email = ['andrew.kreps@gmail.com']
6
6
  spec.description = %q{Markov generation from a Snow Crash corpus.}
@@ -2,7 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe Lita::Handlers::OnewheelSnowcrash, lita_handler: true do
4
4
  it { is_expected.to route_command('snowcrash') }
5
- it { is_expected.to route_command('snowcrash 22') }
5
+ it { is_expected.to route_command('snowcrash 2') }
6
+ it { is_expected.to route_command('snowcrashwords') }
7
+ it { is_expected.to route_command('snowcrashwords 22') }
6
8
 
7
9
  it 'will generate a random-len chain' do
8
10
  send_command 'snowcrash'
@@ -10,8 +12,19 @@ describe Lita::Handlers::OnewheelSnowcrash, lita_handler: true do
10
12
  end
11
13
 
12
14
  it 'will generate a six-word chain' do
13
- send_command 'snowcrash 6'
15
+ send_command 'snowcrashwords 6'
14
16
  expect(replies.last).not_to be nil
15
17
  expect(replies.last.split(' ').count).to be(6)
16
18
  end
19
+
20
+ it 'will generate a sentence chain' do
21
+ send_command 'snowcrash'
22
+ expect(replies.last).not_to be nil
23
+ end
24
+
25
+ it 'will generate a two-sentence chain' do
26
+ send_command 'snowcrash 2'
27
+ expect(replies.last).not_to be nil
28
+ expect(replies.last.split('.').count).to be(2)
29
+ end
17
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-onewheel-snowcrash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kreps