Class: Toodledo::CommandLine::TaskFormatter
- Inherits:
-
Object
- Object
- Toodledo::CommandLine::TaskFormatter
- Defined in:
- lib/toodledo/command_line/task_formatter.rb
Constant Summary collapse
- DUEDATE_BY =
0
- DUEDATE_ON =
1
- DUEDATE_AFTER =
2
- DUEDATE_OPTIONALLY =
3
Instance Method Summary collapse
-
#format(task) ⇒ Object
Formats the task for a command line.
- #readable_duedatemodifier(duedate_modifier) ⇒ Object
-
#readable_priority(priority) ⇒ Object
TODO Refactor using symbols – so much simpler to convert.
-
#readable_repeat(repeat) ⇒ Object
Returns a string matching the numeric repeat code.
-
#readable_status(status) ⇒ Object
Return a readable status given the numeric code.
Instance Method Details
#format(task) ⇒ Object
Formats the task for a command line.
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/toodledo/command_line/task_formatter.rb', line 12 def format(task) fancyp = '!' + readable_priority(task.priority) msg = "<#{task.server_id}> -- #{fancyp}" # TODO Only include [ ] if needed if (task.folder != Folder::NO_FOLDER) msg += " *[#{task.folder.name}]" end if (task.context != Context::NO_CONTEXT) msg += " @[#{task.context.name}]" end if (task.goal != Goal::NO_GOAL) msg += " ^[#{task.goal.name}]" end if (task.repeat != Repeat::NONE) msg += " repeat[#{readable_repeat(task.repeat)}]" end if (task.duedate != nil) fmt = '%m/%d/%Y %I:%M %p' msg += " #[#{readable_duedatemodifier(task.duedatemodifier)}#{task.duedate.strftime(fmt)}]" end if (task.startdate != nil) fmt = '%m/%d/%Y' msg += " startdate[#{task.startdate.strftime(fmt)}]" end if (task.status != Status::NONE) msg += " status[#{readable_status(task.status)}]" end if (task.star) msg += " starred" end if (task.tag != nil) msg += " %[#{task.tag}]" end if (task.parent_id != nil) msg += " parent[#{task.parent.title}]" end if (task.length != nil) msg += " length[#{task.length}]" end if (task.timer != nil) msg += " timer[#{task.timer}]" end if (task.num_children != nil && task.num_children > 0) msg += " children[#{task.num_children}]" end msg += " #{task.title}" if (task.note != nil) msg += "\n #{task.note}" end return msg end |
#readable_duedatemodifier(duedate_modifier) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/toodledo/command_line/task_formatter.rb', line 99 def readable_duedatemodifier(duedate_modifier) # The modifier is passed in as [0..3] but may come back as # <duedate modifier='?'>2011-06-30</duedate> case duedate_modifier when DUEDATE_BY then return '' when DUEDATE_ON then return '=' when DUEDATE_AFTER then return '>' when DUEDATE_OPTIONALLY then return '?' else return duedate_modifier end end |
#readable_priority(priority) ⇒ Object
TODO Refactor using symbols – so much simpler to convert
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/toodledo/command_line/task_formatter.rb', line 82 def readable_priority(priority) case priority when Priority::TOP return 'top' when Priority::HIGH return 'high' when Priority::MEDIUM return 'medium' when Priority::LOW return 'low' when Priority::NEGATIVE return 'negative' else return '' end end |
#readable_repeat(repeat) ⇒ Object
Returns a string matching the numeric repeat code.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/toodledo/command_line/task_formatter.rb', line 119 def readable_repeat(repeat) case repeat when Repeat::NONE '' when Repeat::WEEKLY "weekly" when Repeat::MONTHLY "monthly" when Repeat::YEARLY "yearly" when Repeat::DAILY "daily" when Repeat::BIWEEKLY "biweekly" when Repeat::BIMONTHLY "bimonthly" when Repeat::SEMIANNUALLY "semiannually" when Repeat::QUARTERLY "quarterly" else '' end end |
#readable_status(status) ⇒ Object
Return a readable status given the numeric code.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/toodledo/command_line/task_formatter.rb', line 147 def readable_status(status) case status when Status::NONE 'none' when Status::NEXT_ACTION 'Next Action' when Status::ACTIVE 'Active' when Status::PLANNING 'Planning' when Status::DELEGATED 'Delegated' when Status::WAITING 'Waiting' when Status::HOLD 'Hold' when Status::POSTPONED 'Postponed' when Status::SOMEDAY 'Someday' when Status::CANCELLED 'Cancelled' when Status::REFERENCE 'Reference' end end |