Class: Toodledo::CommandLine::TaskFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/toodledo/command_line/task_formatter.rb

Instance Method Summary collapse

Instance Method Details

#format(task) ⇒ Object

Formats the task for a command line.



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
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
# File 'lib/toodledo/command_line/task_formatter.rb', line 7

def format(task)
  fancyp = '!' + readable_priority(task.priority)
  
  msg = "<#{task.server_id}> -- #{fancyp}"
  
  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 += " \#[#{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 += " tag[#{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_priority(priority) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/toodledo/command_line/task_formatter.rb', line 75

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.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/toodledo/command_line/task_formatter.rb', line 95

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.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/toodledo/command_line/task_formatter.rb', line 123

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