Class: USaidWat::Application::Tally
- Includes:
- CountCommand
- Defined in:
- lib/usaidwat/commands/tally.rb
Instance Attribute Summary
Attributes inherited from Command
Instance Method Summary collapse
-
#initialize(prog) ⇒ Tally
constructor
A new instance of Tally.
- #process(options, args) ⇒ Object
Methods included from CountCommand
Methods inherited from Command
Methods included from Pager
Constructor Details
#initialize(prog) ⇒ Tally
Returns a new instance of Tally.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/usaidwat/commands/tally.rb', line 10 def initialize(prog) prog.command(:tally) do |c| c.alias :t c.option 'count', '-c', '--count', 'Sort output by number of comments' c.action do |args, | process(, args) end end super end |
Instance Method Details
#process(options, args) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/usaidwat/commands/tally.rb', line 22 def process(, args) raise ArgumentError.new('You must specify a username') if args.empty? raise ArgumentError.new('You cannot specify a subreddit when tallying comments') if args.count > 1 username = args.first redditor = client.new(username) quit "#{redditor.username} has no comments." if redditor.comments.empty? partition_data = partition(redditor.comments, ['count']) formatter = USaidWat::CLI::TallyFormatter.new print formatter.format(partition_data) rescue USaidWat::Client::NoSuchUserError quit "No such user: #{username}", :no_such_user end |