Class: Tot::CLI
- Inherits:
-
Thor
- Object
- Thor
- Tot::CLI
- Defined in:
- lib/tot.rb
Overview
}}}
Instance Method Summary collapse
- #add ⇒ Object
- #delete ⇒ Object
- #edit(title) ⇒ Object
-
#initialize(*args) ⇒ CLI
constructor
A new instance of CLI.
- #list ⇒ Object
- #show(title) ⇒ Object
Constructor Details
#initialize(*args) ⇒ CLI
Returns a new instance of CLI.
151 152 153 154 |
# File 'lib/tot.rb', line 151 def initialize(*args) super @todo_manager = TodoManager.new end |
Instance Method Details
#add ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/tot.rb', line 168 def add new_todo = {} new_todo['title'] = Readline.readline('title> ', true).chomp('\n') new_todo['date'] = Time.parse(Utils.datetime_filter(Readline.readline('date> ', true).chomp('\n')).to_s) new_todo['tag'] = Readline.readline('tag (separate by space)> ', true) .chomp('\n').split(' ') tmpfile = "/tmp/tot.markdown" # File.open(tmpfile,"w"){|file| # file.puts "\n\n# This line will be ignored." # } system([ENV['EDITOR'],tmpfile].join(' ')) new_todo['text'] = File.readlines(tmpfile).join print new_todo['text'] File.delete tmpfile @todo_manager.add new_todo end |
#delete ⇒ Object
186 187 188 189 190 |
# File 'lib/tot.rb', line 186 def delete @todo_manager.print_color(true) @todo_manager.delete_at Readline.readline('Which Task?> ',false).chomp('\n').to_i @todo_manager.dump end |
#edit(title) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/tot.rb', line 215 def edit(title) reg = Regexp.new(title,Regexp::IGNORECASE) todos = @todo_manager.find_all{|item| reg.match(item['title'])} if todos.size == 0 puts 'No matched task.' elsif todos.size > 1 puts todos.size.to_s + ' tasks matched.' else todo = todos[0] old_title = todo['title'] if ['title'] todo['title'] = Readline.readline('New Title> ').chomp('\n') elsif ['date'] todo['date'] = Time.parse(Utils.datetime_filter(Readline.readline('date> ', true).chomp('\n')).to_s) elsif ['tag'] todo['tag'] = Readline.readline("tag (old_value: #{todo['tag'].join(' ')})> ", true) .chomp('\n').split(' ') else tmpfile = "/tmp/tot.markdown" File.open(tmpfile,'w'){|file| file.write todo['text']} system([ENV['EDITOR'],tmpfile].join(' ')) todo['text'] = File.readlines(tmpfile).join File.delete tmpfile end puts 'Title: ' + todo['title'] puts 'Date: ' + todo['date'].strftime("%Y/%m/%d %H:%M") puts 'Tags: ' + todo['tag'].to_s puts print todo['text'] @todo_manager.delete_at(@todo_manager.find_index{|obj| obj['title'] == old_title}) @todo_manager.add todo end end |
#list ⇒ Object
158 159 160 161 162 163 164 165 |
# File 'lib/tot.rb', line 158 def list if ['tag'] @todo_manager.find_all! do |todo| [:tag].all?{|i| todo['tag'].include? i} end end @todo_manager.print_color(false) end |
#show(title) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/tot.rb', line 196 def show(title) reg = Regexp.new(title,Regexp::IGNORECASE) todos = @todo_manager.find_all{|item| reg.match(item['title'])} if todos.size == 0 puts 'No matched task.' elsif todos.size > 1 puts 'Several tasks matched.' else todo = todos[0] puts 'Title: ' + todo['title'] puts 'Date: ' + todo['date'].strftime("%Y/%m/%d %H:%M") puts print todo['text'] end end |