-
-
Save emiliecoudrat/6bcdb14a6eff8b8575f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require_relative "task_repository" | |
| require_relative "display" | |
| require_relative "controller" | |
| # Creer fausse base de données | |
| task_repository = TaskRepository.new | |
| # Creer un Display | |
| display = Display.new | |
| # Creer un controlleur | |
| controller = Controller.new( | |
| task_repository, display) | |
| while true | |
| controller.list_tasks | |
| puts "Que voulez-vous faire maintenant?" | |
| puts "1 - Ajouter une tâche" | |
| puts "2 - Terminer une tâche" | |
| action = gets.chomp.to_i | |
| if action == 1 | |
| controller.add_task | |
| elsif action == 2 | |
| controller.mark_task_as_done | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require_relative "task" | |
| class Controller | |
| def initialize(task_repository, display) | |
| # Injection de dependance | |
| @task_repository = task_repository | |
| @display = display | |
| end | |
| def list_tasks | |
| # recupere toutes les tasks | |
| tasks = @task_repository.tasks | |
| # affiche | |
| @display.print_tasks(tasks) | |
| end | |
| def add_task | |
| description = @display.ask_user_for_new_task_description | |
| task = Task.new(description) | |
| @task_repository.add_task(task) | |
| end | |
| def mark_task_as_done | |
| index = @display.ask_user_for_task_id_to_mark_as_done | |
| if index | |
| task = @task_repository.tasks[index] | |
| task.mark_as_done if task | |
| end | |
| end | |
| # TODO: cocher, supprimer | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require_relative "task" | |
| class Controller | |
| def initialize(task_repository, display) | |
| # Injection de dependance | |
| @task_repository = task_repository | |
| @display = display | |
| end | |
| def list_tasks | |
| # recupere toutes les tasks | |
| tasks = @task_repository.tasks | |
| # affiche | |
| @display.print_tasks(tasks) | |
| end | |
| def add_task | |
| description = @display.ask_user_for_new_task_description | |
| task = Task.new(description) | |
| @task_repository.add_task(task) | |
| end | |
| def mark_task_as_done | |
| index = @display.ask_user_for_task_id_to_mark_as_done | |
| if index | |
| task = @task_repository.tasks[index] | |
| task.mark_as_done if task | |
| end | |
| end | |
| # TODO: cocher, supprimer | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Task | |
| attr_reader :description, :done | |
| def initialize(description) | |
| @description = description | |
| @done = false | |
| end | |
| def mark_as_done | |
| @done = true | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TaskRepository | |
| attr_reader :tasks | |
| def initialize | |
| @tasks = [] # Stocke instances de class Task | |
| end | |
| def add_task(task) | |
| @tasks << task | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment