Class: Twat::Subcommands::Base
- Inherits:
-
Object
- Object
- Twat::Subcommands::Base
show all
- Includes:
- Exceptions
- Defined in:
- lib/twat/subcommands/base.rb
Direct Known Subclasses
Add, Config, Delete, Finger, Follow, FollowTag, List, Mentions, Set, Track, Update, UpdateConfig, Version
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Exceptions
#with_handled_exceptions
Constructor Details
#initialize(argv) ⇒ Base
Returns a new instance of Base.
21
22
23
|
# File 'lib/twat/subcommands/base.rb', line 21
def initialize(argv)
@argv=argv
end
|
Instance Attribute Details
#opts ⇒ Object
Returns the value of attribute opts.
19
20
21
|
# File 'lib/twat/subcommands/base.rb', line 19
def opts
@opts
end
|
Instance Method Details
#args ⇒ Object
103
104
105
106
107
|
# File 'lib/twat/subcommands/base.rb', line 103
def args
@args ||= $args
end
|
#auth! ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/twat/subcommands/base.rb', line 48
def auth!
Twitter.configure do |twit|
config.account.each do |key, value|
twit.send("#{key}=", value)
end
config.endpoint.consumer_info.each do |key, value|
twit.send("#{key}=", value)
end
twit.endpoint = config.endpoint.url
end
end
|
#beep ⇒ Object
60
61
62
|
# File 'lib/twat/subcommands/base.rb', line 60
def beep
print "\a"
end
|
#config ⇒ Object
95
96
97
|
# File 'lib/twat/subcommands/base.rb', line 95
def config
@config ||= ::Twat::Config.new
end
|
#deentitize(text) ⇒ Object
88
89
90
91
92
93
|
# File 'lib/twat/subcommands/base.rb', line 88
def deentitize(text)
{"<" => "<", ">" => ">", "&" => "&", """ => '"' }.each do |k,v|
text.gsub!(k, v)
end
text
end
|
#enable_readline! ⇒ Object
109
110
111
|
# File 'lib/twat/subcommands/base.rb', line 109
def enable_readline!
@reader = ReadlineNG::Reader.new
end
|
Format a tweet all pretty like
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/twat/subcommands/base.rb', line 69
def format(twt, idx = nil)
idx = pad(idx) if idx
text = deentitize(twt.text)
if config.colors?
buf = idx ? "#{idx.cyan}:" : ""
if twt.as_user == config.account_name.to_s
buf += "#{twt.as_user.bold.blue}: #{text}"
elsif text.mentions?(config.account_name)
buf += "#{twt.as_user.bold.red}: #{text}"
else
buf += "#{twt.as_user.bold.cyan}: #{text}"
end
buf.colorise!
else
buf = idx ? "#{idx}: " : ""
buf += "#{twt.as_user}: #{text}"
end
end
|
#needs_arguments(n) ⇒ Object
31
32
33
34
35
|
# File 'lib/twat/subcommands/base.rb', line 31
def needs_arguments(n)
unless @argv.length == n
usage_and_exit!
end
end
|
#needs_at_least(n) ⇒ Object
37
38
39
40
41
|
# File 'lib/twat/subcommands/base.rb', line 37
def needs_at_least(n)
unless @argv.length >= n
usage_and_exit!
end
end
|
#pad(n) ⇒ Object
64
65
66
|
# File 'lib/twat/subcommands/base.rb', line 64
def pad(n)
"%02d" % n
end
|
#reader ⇒ Object
113
114
115
|
# File 'lib/twat/subcommands/base.rb', line 113
def reader
@reader
end
|
#run! ⇒ Object
25
26
27
28
29
|
# File 'lib/twat/subcommands/base.rb', line 25
def run!
with_handled_exceptions(args) do
run
end
end
|
#usage ⇒ Object
117
118
119
|
# File 'lib/twat/subcommands/base.rb', line 117
def usage
puts self.class.usage
end
|
#usage_and_exit! ⇒ Object
43
44
45
46
|
# File 'lib/twat/subcommands/base.rb', line 43
def usage_and_exit!
usage
exit
end
|