Class: USaidWat::Application::Timeline
- Defined in:
- lib/usaidwat/commands/timeline.rb
Instance Attribute Summary
Attributes inherited from Command
Instance Method Summary collapse
-
#initialize(prog) ⇒ Timeline
constructor
A new instance of Timeline.
- #process(options, args) ⇒ Object
Methods inherited from Command
Methods included from Pager
Constructor Details
#initialize(prog) ⇒ Timeline
Returns a new instance of Timeline.
4 5 6 7 8 9 10 11 |
# File 'lib/usaidwat/commands/timeline.rb', line 4 def initialize(prog) prog.command(:timeline) do |c| c.action do |args, | dispatch_process(:process, , args) end end super end |
Instance Method Details
#process(options, args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/usaidwat/commands/timeline.rb', line 13 def process(, args) raise ArgumentError.new('You must specify a username') if args.empty? username = args.shift redditor = client.new(username) comments = redditor.comments quit "#{username} has no comments." if comments.empty? buckets = comments_by_days_and_hours(comments) times = Array.new(7) { Array.new(24, 0) } buckets.each do |v| d, h = v times[d][h] += 1 end formatter = USaidWat::CLI::TimelineFormatter.new puts formatter.format(times) rescue USaidWat::Client::NoSuchUserError quit "No such user: #{username}", :no_such_user end |