-
Notifications
You must be signed in to change notification settings - Fork 1
/
output.coffee
57 lines (44 loc) · 1.3 KB
/
output.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# English stuff
_tensify = require "tensify"
tensify = (verbial_phrase, how)->
words = verbial_phrase.split " "
[verb, more...] = words
[_tensify(verb)[how], more...].join " "
a_an = (what)->
if what.match /^\s*[aeiou]/
"an #{what}"
else
"a #{what}"
# Array helpers
unique = require "array-unique"
choose = (arr)->
arr[~~(Math.random() * arr.length)]
# String helpers
String::ucfirst = ->
@charAt(0).toUpperCase() + @slice(1)
# Output information about a subject
module.exports = (subject)->
o = console.log
o "Hey, look, #{a_an subject.singular}!"
if subject.adjectives.length
o ""
o "I think #{subject.plural} are...\n #{subject.adjectives.join "\n "}"
if subject.verbs.length
o ""
o "What do #{subject.plural} do? They...\n #{subject.verbs.join "\n "}"
some_adjectives = ->
unique (choose subject.adjectives for [0..Math.random()*3])
some_action = ->
choose subject.verbs
o ""
if subject.adjectives.length
for [0..5]
o "There is #{a_an some_adjectives().join ", "} #{subject.singular}."
else
o "I don't know how to describe #{a_an subject.singular}. Sorry."
o ""
if subject.verbs.length
for [0..5]
o "#{a_an some_adjectives().join ", "} #{subject.singular} #{tensify(some_action(), "past")}.".ucfirst()
else
o "I don't know what #{subject.plural} do. Sorry."