Class: GoogleTasks::CLI
- Inherits:
-
Thor
- Object
- Thor
- GoogleTasks::CLI
- Includes:
- Thor::Actions
- Defined in:
- lib/goot/cli.rb
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(*args) ⇒ CLI
constructor
A new instance of CLI.
- #list ⇒ Object
- #summary ⇒ Object
- #toggle(index) ⇒ Object
Constructor Details
#initialize(*args) ⇒ CLI
Returns a new instance of CLI.
4 5 6 7 |
# File 'lib/goot/cli.rb', line 4 def initialize(*args) super @api = GoogleTasks::GoogleAPI.new end |
Instance Method Details
#clear ⇒ Object
72 73 74 75 76 77 |
# File 'lib/goot/cli.rb', line 72 def clear tasklist = @api.get_tasklist([:tasklist]) @api.clear_tasks(tasklist) invoke :list, [], :tasklist => [:tasklist] end |
#list ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/goot/cli.rb', line 12 def list tab = ' ' depths = {} tasklist = @api.get_tasklist([:tasklist]) tasks = @api.get_tasks(tasklist) say tasklist.title, :green tasks.each.with_index do |task, i| next if task.deleted status = task.status == 'completed' ? '✓' : '▢' depth = 1 depth += depths[task.parent] if depths.include? task.parent depths[task.id] = depth say "#{tab * depth} #{status} #{i}: #{task.title}" say "#{tab * (depth + 1)} Notes: #{task.notes}", :yellow if task.notes end end |
#summary ⇒ Object
36 37 38 39 40 41 |
# File 'lib/goot/cli.rb', line 36 def summary @api.get_lists.each.with_index do |tasklist, i| tasks = @api.get_tasks(tasklist) say "#{i} #{tasklist.title} (#{tasks.size})" end end |
#toggle(index) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/goot/cli.rb', line 46 def toggle(index) tasklist = @api.get_tasklist([:tasklist]) tasks = @api.get_tasks(tasklist).map(&:to_hash) task = tasks[index.to_i] task['status'] = task['completed'].nil? ? 'completed' : 'needsAction' task.delete 'completed' @api.update_task(tasklist, task) toggle_children = lambda do |parent| children = tasks.select { |t| t['parent'] == parent['id'] } children.each do |t| t['status'] = task['status'] t.delete 'completed' @api.update_task(tasklist, t) toggle_children.call(t) end end toggle_children.call(task) invoke :list, [], :tasklist => [:tasklist] end |