Class: GoogleTaskCLI

Inherits:
Object
  • Object
show all
Defined in:
lib/gtasks.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GoogleTaskCLI

Returns a new instance of GoogleTaskCLI.



347
348
349
# File 'lib/gtasks.rb', line 347

def initialize(options={})
  @gtasks = GoogleTask.new(options)
end

Instance Method Details

#add(task_name) ⇒ Object



386
387
388
389
# File 'lib/gtasks.rb', line 386

def add(task_name)
  @gtasks.add(task_name)
  list
end

#choiceObject



418
419
420
421
422
# File 'lib/gtasks.rb', line 418

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

#clearObject



391
392
393
394
# File 'lib/gtasks.rb', line 391

def clear
  @gtasks.clear
  list
end

#delete(param) ⇒ Object



407
408
409
410
411
412
413
414
415
416
# File 'lib/gtasks.rb', line 407

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



396
397
398
399
400
401
402
403
404
405
# File 'lib/gtasks.rb', line 396

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



351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/gtasks.rb', line 351

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_allObject



370
371
372
# File 'lib/gtasks.rb', line 370

def list_all
  @gtasks.show
end

#listsObject



366
367
368
# File 'lib/gtasks.rb', line 366

def lists
  print_selector @gtasks.lists.map{|e| e["title"]}
end


374
375
376
377
378
379
380
381
382
383
384
# File 'lib/gtasks.rb', line 374

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