class Wip::CLI
Public Instance Methods
complete(todo_id)
click to toggle source
# File lib/wip/cli.rb, line 14 def complete(todo_id) todo = options.undo ? Wip::Todo.uncomplete(todo_id) : Wip::Todo.complete(todo_id) puts todo.description end
delete(todo_id)
click to toggle source
# File lib/wip/cli.rb, line 26 def delete(todo_id) todo = Wip::Todo.delete(todo_id) puts todo.description end
done(body)
click to toggle source
# File lib/wip/cli.rb, line 20 def done(body) todo = Wip::Todo.create(body: body, completed_at: DateTime.now) puts todo.description end
me()
click to toggle source
# File lib/wip/cli.rb, line 32 def me print_user_profile Wip::User.viewer(todos: { "order" => "created_at:desc" }) end
print_user_profile(user)
click to toggle source
# File lib/wip/cli.rb, line 77 def print_user_profile(user) puts "👤 #{user.name}, aka @#{user.username} (User #{user.id})" puts "🌍 Lives in #{user.time_zone} where it currently is #{user.tz.to_local(Time.now).strftime("%H:%M")}" puts "✅ #{user.completed_todos_count} completed todos" if user.streaking puts "#{user.streak_icon} On a streak of #{user.streak}" else last_todo = user.done_todos.first if last_todo.nil? puts "#{user.streak_icon} No todo" else puts "#{user.streak_icon} Last todo created @ #{last_todo.created_at}" end end puts "🔗 #{user.url}" end
todo(body)
click to toggle source
# File lib/wip/cli.rb, line 37 def todo(body) todo = Wip::Todo.create(body: body) puts todo.description end
todos()
click to toggle source
# File lib/wip/cli.rb, line 49 def todos todos_options = options.slice("completed", "filter", "limit", "order") user = options.username.nil? ? Wip::User.viewer(todos: todos_options) : Wip::User.find(username: options.username, todos: todos_options) if options.interactive prompt = TTY::Prompt.new options = user.todos.inject({}) do |h, todo| h[todo.description] = todo.id h end choice = prompt.multi_select("Toggle todos?", options, per_page: todos_options["limit"]) puts "No change" if choice.empty? choice.each do |todo_id| todo = user.todos.find { |todo| todo.id == todo_id } todo.toggle puts todo.description end else user.todos.each { |todo| puts todo.description } end end
user(identifier)
click to toggle source
# File lib/wip/cli.rb, line 71 def user(identifier) user = identifier.to_i > 0 ? Wip::User.find(identifier.to_i) : Wip::User.find(username: identifier) print_user_profile user end