Module: Ptf::Commands::List
- Defined in:
- lib/ptf/commands/list.rb
Class Method Summary collapse
- .generate_list_display(open, closed) ⇒ Object
- .get_metadata_for_group(group, flag) ⇒ Object
- .list(delimiter, open, closed) ⇒ Object
- .sort_closed_task_arr(task_arr) ⇒ Object
- .sort_open_task_arr(task_arr) ⇒ Object
Class Method Details
.generate_list_display(open, closed) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ptf/commands/list.rb', line 68 def generate_list_display(open, closed) list_display = "" first = true, past_due = false, have_due_date = true open.each do |t| if have_due_date && t.due_date.nil? have_due_date = false list_display += "\n" unless first list_display += "=========== NoDate ===========\n\n" end if have_due_date && first && t.due_date <= DateTime.now first = false past_due = true list_display += "============ Past ============\n\n" elsif first && have_due_date first = false list_display += "========== Upcoming ==========\n\n" end if have_due_date && past_due && t.due_date > DateTime.now past_due = false list_display += "\n========== Upcoming ==========\n\n" end list_display += "#{t.due_date_list_format} #{t.title} (#{t.group.abbreviation} #{t.id})\n" end = true closed.each do |t| if list_display += "\n" unless list_display == "" list_display += "=========== Closed ===========\n\n" = false end list_display += "#{t.completed_at_list_format} #{t.title} (#{t.group.abbreviation} #{t.id})\n" end list_display end |
.get_metadata_for_group(group, flag) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ptf/commands/list.rb', line 6 def (group, flag) raise ArgumentError, "Group #{group} does not exist." unless Ptf::Group.group_exist?(group) group_name = Ptf::Group.get_group(group).name open_group_path = File.join(Ptf::FileSystem., group_name) open_group_dir = Dir.new(open_group_path) closed_group_path = File.join(Ptf::FileSystem., group_name) closed_group_dir = Dir.new(closed_group_path) open_tasks = [] closed_tasks = [] if flag == :open || flag == :both open_group_dir.to_a.each do |file| path = File.join(open_group_path, file) if File.file? path open_tasks.push Ptf::MetadataFile.create_from_file(path) end end end if flag == :closed || flag == :both closed_group_dir.to_a.each do |file| path = File.join(closed_group_path, file) if File.file? path closed_tasks.push Ptf::MetadataFile.create_from_file(path) end end end [open_tasks, closed_tasks] end |
.list(delimiter, open, closed) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/ptf/commands/list.rb', line 109 def list(delimiter, open, closed) if open && closed flag = :both elsif closed flag = :closed else flag = :open end if delimiter.downcase == "all" all_groups = Ptf::Group.all_groups open_tasks = [] closed_tasks = [] all_groups.each do |g| open, closed = (g.name, flag) open_tasks.concat open closed_tasks.concat closed end else if !Ptf::Group.group_exist?(delimiter) return "Group #{delimiter} does not exist." end open_tasks, closed_tasks = (delimiter, flag) end open_tasks = sort_open_task_arr(open_tasks) closed_tasks = sort_closed_task_arr(closed_tasks) return generate_list_display(open_tasks, closed_tasks) end |
.sort_closed_task_arr(task_arr) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/ptf/commands/list.rb', line 58 def sort_closed_task_arr(task_arr) sorted_arr = task_arr sorted_arr.sort! do |a,b| b.completed_at <=> a.completed_at end sorted_arr end |
.sort_open_task_arr(task_arr) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ptf/commands/list.rb', line 40 def sort_open_task_arr(task_arr) sorted_arr = task_arr sorted_arr.sort! do |a,b| if a.due_date.nil? && b.due_date.nil? a.created_at <=> b.created_at elsif a.due_date.nil? 1 elsif b.due_date.nil? -1 else a.due_date <=> b.due_date end end sorted_arr end |