lita-poetry 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +14 -6
- data/lib/lita/handlers/poetry.rb +8 -25
- data/lita-poetry.gemspec +1 -1
- data/spec/lita/handlers/poetry_spec.rb +73 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fae74b4091fa03b08ddc0dc186c2af8420797254
|
4
|
+
data.tar.gz: 4d148bdce58396c0383a458a4d3a028bf73455c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 024137fb66a1864e168c10d99f77e3e466a67928f103c3805ab050c046c39544b5b5587e172fcc7ad4b10355039a888b04019a2fb55ab300f94dde83c192d212
|
7
|
+
data.tar.gz: 0769821b91b536cec99d39c586530c722b6e542d07d4ae2716dba193c691502af991fc0b1949069d6d75c0e9376850f437a79c8b6c7afbe6be85e33a6d6fb573
|
data/README.md
CHANGED
@@ -1,6 +1,18 @@
|
|
1
|
+
[](http://badge.fury.io/rb/lita-poetry) [](https://coveralls.io/r/chriswoodrich/lita-poetry?branch=v0.0.1) [](https://travis-ci.org/chriswoodrich/lita-poetry)
|
2
|
+
|
1
3
|
# lita-poetry
|
2
4
|
|
3
|
-
|
5
|
+
Lita-poetry passively listens for haikus (accidential or not) and alerts the channel when a haiku has formed.
|
6
|
+
|
7
|
+
```
|
8
|
+
Jimmy > Flash of steel stills me
|
9
|
+
Jimmy > calmness mirrors the ocean
|
10
|
+
Jimmy > I await the waves
|
11
|
+
Lita > Garth, that was a haiku!
|
12
|
+
```
|
13
|
+
|
14
|
+

|
15
|
+
|
4
16
|
|
5
17
|
## Installation
|
6
18
|
|
@@ -12,11 +24,7 @@ gem "lita-poetry"
|
|
12
24
|
|
13
25
|
## Configuration
|
14
26
|
|
15
|
-
|
16
|
-
|
17
|
-
## Usage
|
18
|
-
|
19
|
-
TODO: Describe the plugin's features and how to use them.
|
27
|
+
No configuration is needed in this version.
|
20
28
|
|
21
29
|
## License
|
22
30
|
|
data/lib/lita/handlers/poetry.rb
CHANGED
@@ -39,34 +39,21 @@ module Lita
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def process_sentence(sentence)
|
42
|
-
|
42
|
+
sentence.gsub!("'", "")
|
43
|
+
sentence.gsub!(",","")
|
44
|
+
sentence.gsub!(".","")
|
43
45
|
words = sentence.split(' ')
|
44
|
-
|
45
46
|
return words.map{|word| count_syllables(word)}.inject(:+)
|
46
|
-
|
47
47
|
end
|
48
48
|
|
49
49
|
|
50
50
|
def count_syllables(word)
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
word = word[0...-3]
|
58
|
-
end
|
59
|
-
|
60
|
-
got = word.scan(tokenizer)
|
61
|
-
len += got.size()
|
62
|
-
|
63
|
-
if got.size() > 1 and got[-1] == ['e'] and
|
64
|
-
word[-1].chr() == 'e' and
|
65
|
-
word[-2].chr() != 'l' then
|
66
|
-
len -= 1
|
67
|
-
end
|
68
|
-
|
69
|
-
return len
|
52
|
+
word.downcase!
|
53
|
+
return 1 if word.length <= 3
|
54
|
+
word.sub!(/(?:[^laeiouy]es|ed|[^laeiouy]e)$/, '')
|
55
|
+
word.sub!(/^y/, '')
|
56
|
+
word.scan(/[aeiouy]{1,2}/).size
|
70
57
|
|
71
58
|
end
|
72
59
|
|
@@ -78,12 +65,8 @@ module Lita
|
|
78
65
|
(3 - length).times do
|
79
66
|
redis.rpush('data', MultiJson.dump({'id' => 0, 'count' => 0 }))
|
80
67
|
end
|
81
|
-
|
82
68
|
end
|
83
|
-
|
84
69
|
end
|
85
|
-
|
86
|
-
|
87
70
|
end
|
88
71
|
Lita.register_handler(Poetry)
|
89
72
|
end
|
data/lita-poetry.gemspec
CHANGED
@@ -9,13 +9,83 @@ describe Lita::Handlers::Poetry, lita_handler: true do
|
|
9
9
|
describe '#process' do
|
10
10
|
before {robot.trigger(:loaded)}
|
11
11
|
it 'tells Garth or the poetic user that (s)he has written a Haiku' do
|
12
|
-
|
13
12
|
send_message("dainty daffodil")
|
14
|
-
send_message("your golden trumpet
|
13
|
+
send_message("your golden trumpet fanfares")
|
15
14
|
send_message("the dawning of spring")
|
16
|
-
|
17
15
|
expect(replies.last).to eq('Garth, that was a haiku!')
|
18
16
|
end
|
17
|
+
|
18
|
+
it 'does nothing when 3 consective lines do not have a 5-7-5 pattern' do
|
19
|
+
|
20
|
+
send_message("Friends, Romans, countrymen, lend me your ears;")
|
21
|
+
send_message("I come to bury Caesar, not to praise him.")
|
22
|
+
send_message("The evil that men do lives after them;")
|
23
|
+
send_message("The good is oft interred with their bones;")
|
24
|
+
send_message("So let it be with Caesar. The noble Brutus")
|
25
|
+
send_message("Hath told you Caesar was ambitious:")
|
26
|
+
send_message("If it were so, it was a grievous fault,")
|
27
|
+
send_message("And grievously hath Caesar answer’d it.")
|
28
|
+
|
29
|
+
expect(replies.size).to eq(0)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'handles a varierty of different ways to get to 5-7-5' do
|
33
|
+
|
34
|
+
send_message("Amongst these are the")
|
35
|
+
send_message("Haiku Hating Haiku Bros")
|
36
|
+
send_message("Oh the irony.")
|
37
|
+
|
38
|
+
send_message("To spread their evil")
|
39
|
+
send_message("They hate haiku through Hiakus")
|
40
|
+
send_message("Here is their worst deeds.")
|
41
|
+
|
42
|
+
send_message("haiku are easy")
|
43
|
+
send_message("But some times they dont make sense")
|
44
|
+
send_message("Refrigerator")
|
45
|
+
|
46
|
+
send_message("In the ponds cool depths")
|
47
|
+
send_message("the happy frog plays in spring")
|
48
|
+
send_message("his life, a slow game.")
|
49
|
+
|
50
|
+
send_message("Summer’s arid heat")
|
51
|
+
send_message("the dry parched earth welcomes me")
|
52
|
+
send_message("my blood nourishing.")
|
53
|
+
|
54
|
+
send_message("Sheltering cherry")
|
55
|
+
send_message("my last breath stirs your blossom")
|
56
|
+
send_message("my soul ascends. Meh.")
|
57
|
+
|
58
|
+
send_message("Autumn maple leaves")
|
59
|
+
send_message("their colours, like the harvest")
|
60
|
+
send_message("remind me of home.")
|
61
|
+
|
62
|
+
send_message("A soul ship finds me")
|
63
|
+
send_message("crystal waters call my name")
|
64
|
+
send_message("I am dragged below.")
|
65
|
+
|
66
|
+
send_message("Noble enemy")
|
67
|
+
send_message("I mourn your loss as I mourned")
|
68
|
+
send_message("for my first-born son.")
|
69
|
+
|
70
|
+
send_message("The old carp is wise")
|
71
|
+
send_message("he whispers his dark secrets")
|
72
|
+
send_message("only the wind hears.")
|
73
|
+
|
74
|
+
send_message("The dark tiger stalks")
|
75
|
+
send_message("my soul quivers in the air")
|
76
|
+
send_message("just for a moment.")
|
77
|
+
|
78
|
+
send_message("Raindrops on the lake")
|
79
|
+
send_message("a universe of ripples")
|
80
|
+
send_message("center touching all.")
|
81
|
+
|
82
|
+
send_message("Leaves turn green to gold")
|
83
|
+
send_message("not to end but to transform")
|
84
|
+
send_message("as flesh rots to dust.")
|
85
|
+
|
86
|
+
expect(replies.size).to eq(13)
|
87
|
+
end
|
88
|
+
|
19
89
|
end
|
20
90
|
|
21
91
|
|