-
Notifications
You must be signed in to change notification settings - Fork 0
/
intro.rb
executable file
·55 lines (43 loc) · 976 Bytes
/
intro.rb
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
#!/usr/bin/env ruby
class IntroTweeter
def initialize(arguments, stdin)
@arguments = arguments
@stdin = stdin
end
def run
if arguments_valid?
puts introduce(@arguments.first).join("\n\n")
else
puts "Usage: intro [username]"
end
end
protected
def arguments_valid?
true if @arguments.length == 1
end
def names
File.open("regulars.txt", "r") do |f|
f.readlines.map(&:strip)
end
end
def prefix(new_name, count)
"@#{new_name} please meet the http://MalazanTweeps.com Regulars (#{count}):"
end
def introduce(new_name)
tweets = []
count = 1
tweet = prefix(new_name, count)
names.sort_by { rand }.each do |name|
if (tweet + " @" + name).length <= 140
tweet += " @" + name
else
tweets << tweet
count += 1
tweet = prefix(new_name, count)
end
end
tweets
end
end
app = IntroTweeter.new(ARGV, STDIN)
app.run