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.



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

def initialize(options={})
  @gtasks = GoogleTask.new(options)
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

#choiceObject



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

#clearObject



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_allObject



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

def list_all
  @gtasks.show
end

#listsObject



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

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


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