Class: GoogleTaskCLI
- Inherits:
-
Object
- Object
- GoogleTaskCLI
- Defined in:
- lib/gtasks.rb
Instance Method Summary collapse
- #add(task_name) ⇒ Object
- #choice ⇒ Object
- #clear ⇒ Object
- #delete(param) ⇒ Object
- #done(param) ⇒ Object
-
#initialize(options = {}) ⇒ GoogleTaskCLI
constructor
A new instance of GoogleTaskCLI.
- #list(scope = 'default') ⇒ Object
- #list_all ⇒ Object
- #lists ⇒ Object
- #print_list(list_id) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ GoogleTaskCLI
Returns a new instance of GoogleTaskCLI.
348 349 350 |
# File 'lib/gtasks.rb', line 348 def initialize(={}) @gtasks = GoogleTask.new() end |
Instance Method Details
#add(task_name) ⇒ Object
387 388 389 390 |
# File 'lib/gtasks.rb', line 387 def add(task_name) @gtasks.add(task_name) list end |
#choice ⇒ Object
419 420 421 422 423 |
# File 'lib/gtasks.rb', line 419 def choice items = @gtasks.tasks.map{|e| e["title"]} rand_index = ((rand * items.size) + 1).to_i build_selector_format(rand_index, items[rand_index]).display end |
#clear ⇒ Object
392 393 394 395 |
# File 'lib/gtasks.rb', line 392 def clear @gtasks.clear list end |
#delete(param) ⇒ Object
408 409 410 411 412 413 414 415 416 417 |
# File 'lib/gtasks.rb', line 408 def delete(param) # 数字オンリーだったら番号指定のタスクdoneと認識する if param =~ /^[0-9]+$/ @gtasks.delete(param.to_i) else # それ意外は正規表現として認識、タスク名がマッチしたものをすべて完了する @gtasks.delete_if Regexp.new(param.to_s) end list end |
#done(param) ⇒ Object
397 398 399 400 401 402 403 404 405 406 |
# File 'lib/gtasks.rb', line 397 def done(param) # 数字オンリーだったら番号指定のタスクdoneと認識する if param =~ /^[0-9]+$/ @gtasks.done(param.to_i) else # それ以外は正規表現として認識、タスク名が正規表現にマッチしたものをすべて完了する @gtasks.done_if Regexp.new(param.to_s) end list end |
#list(scope = 'default') ⇒ Object
352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
# File 'lib/gtasks.rb', line 352 def list(scope = 'default') case scope when 'all' list_all when /^[0-9]+/ list_number = scope.to_i list_id = @gtasks.lists[list_number]["id"] print_list(list_id) when 'default' print_list('@default') else raise ArgumentError end end |
#list_all ⇒ Object
371 372 373 |
# File 'lib/gtasks.rb', line 371 def list_all @gtasks.show end |
#lists ⇒ Object
367 368 369 |
# File 'lib/gtasks.rb', line 367 def lists print_selector @gtasks.lists.map{|e| e["title"]} end |
#print_list(list_id) ⇒ Object
375 376 377 378 379 380 381 382 383 384 385 |
# File 'lib/gtasks.rb', line 375 def print_list(list_id) @gtasks.tasks(list_id).each_with_index{ |task, index| title = task["title"] if task["status"] == 'completed' done_string = '☑' else done_string = '☐' end puts "[#{index}] #{done_string} #{title}" } end |