Module: RubyTodo::NotebookCommands
- Included in:
- CLI
- Defined in:
- lib/ruby_todo/commands/notebook_commands.rb
Instance Method Summary collapse
Instance Method Details
#notebook_create(name) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/ruby_todo/commands/notebook_commands.rb', line 5 def notebook_create(name) notebook = Notebook.new(name: name) if notebook.save puts "Created notebook: #{name}".green notebook else puts "Error creating notebook: #{notebook.errors..join(", ")}".red nil end end |
#notebook_list ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby_todo/commands/notebook_commands.rb', line 16 def notebook_list notebooks = Notebook.all return say "No notebooks found".yellow if notebooks.empty? table = TTY::Table.new( header: ["ID", "Name", "Tasks", "Created At", "Default"], rows: notebooks.map do |notebook| [ notebook.id, notebook.name, notebook.tasks.count, notebook.created_at, notebook.is_default? ? "✓" : "" ] end ) puts table.render(:ascii) end |
#notebook_set_default(name) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/ruby_todo/commands/notebook_commands.rb', line 35 def notebook_set_default(name) notebook = Notebook.find_by(name: name) if notebook notebook.make_default! say "Successfully set '#{name}' as the default notebook".green else say "Notebook '#{name}' not found".red end end |