Module: Cli::Lists
- Included in:
- Base
- Defined in:
- lib/cli/lists.rb
Instance Method Summary collapse
- #ask_for_list ⇒ Object
- #inbox_first(tasks_list) ⇒ Object
- #list_title_for(list) ⇒ Object
- #lists ⇒ Object
- #lists_list ⇒ Object
- #show_list_list(tasks_lists) ⇒ Object
- #show_task_list(list, tasks) ⇒ Object
Instance Method Details
#ask_for_list ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/cli/lists.rb', line 14 def ask_for_list lists_list list_index = ask("Add to list?") if list_index.to_i == 1 || list_index.empty? 'inbox' else lists[list_index.to_i-2] end end |
#inbox_first(tasks_list) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/cli/lists.rb', line 55 def inbox_first(tasks_list) inbox = tasks_list.find{ |l, t| l == 'inbox' } if inbox show_task_list(inbox[0], inbox[1]) tasks_list.delete_if{|l, t| l == 'inbox' } end tasks_list end |
#list_title_for(list) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cli/lists.rb', line 34 def list_title_for(list) if list == 'inbox' list = OpenStruct.new({ title: "Inbox", id: '' }) else list = lists.find{ |l| l.id == list } end puts_padded list.title, " ", list.id puts_padded '', "=" end |
#lists ⇒ Object
4 5 6 |
# File 'lib/cli/lists.rb', line 4 def lists @lists ||= client.lists end |
#lists_list ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/cli/lists.rb', line 26 def lists_list puts "1. Inbox" lists.each_with_index do |list, idx| puts "#{idx+2}. #{list.title} (ID: #{list.id})" end end |
#show_list_list(tasks_lists) ⇒ Object
8 9 10 11 12 |
# File 'lib/cli/lists.rb', line 8 def show_list_list(tasks_lists) inbox_first(tasks_lists).each do |list, tasks| show_task_list(list, tasks) end end |
#show_task_list(list, tasks) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/cli/lists.rb', line 45 def show_task_list(list, tasks) list_title_for(list) tasks.sort_by {|t| t.created_at.to_i }.reverse.each do |task| puts_padded " - #{task.title}", " ", task.id end puts ''.ljust(80, " ") end |