Class: USaidWat::Application::Info

Inherits:
Command
  • Object
show all
Defined in:
lib/usaidwat/commands/info.rb

Instance Attribute Summary

Attributes inherited from Command

#client

Instance Method Summary collapse

Methods inherited from Command

inherited, #quit, subclasses

Methods included from Pager

#page

Constructor Details

#initialize(prog) ⇒ Info

Returns a new instance of Info.



7
8
9
10
11
12
13
14
# File 'lib/usaidwat/commands/info.rb', line 7

def initialize(prog)
  prog.command(:info) do |c|
    c.action do |args, options|
      process(options, args)
    end
  end
  super
end

Instance Method Details

#process(options, args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/usaidwat/commands/info.rb', line 16

def process(options, args)
  raise ArgumentError.new('You must specify a username') if args.empty?
  username = args.shift

  redditor = client.new(username)
  created_at = redditor.created_at.strftime("%b %d, %Y %H:%M %p")
  puts "Created: #{created_at} (#{redditor.age})"
  printf "Link Karma: %d\n", redditor.link_karma
  printf "Comment Karma: %d\n", redditor.comment_karma
rescue USaidWat::Client::NoSuchUserError
  quit "No such user: #{username}", :no_such_user
end