Class: Ruby::Pomodoro::Tasks::Editor
- Inherits:
-
Object
- Object
- Ruby::Pomodoro::Tasks::Editor
- Defined in:
- lib/ruby/pomodoro/tasks/editor.rb
Instance Attribute Summary collapse
-
#editor ⇒ Object
readonly
Returns the value of attribute editor.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#tasks_repo ⇒ Object
readonly
Returns the value of attribute tasks_repo.
Instance Method Summary collapse
-
#edit ⇒ TrueClass
Open editor and save tasks from tmp file to task_repo.
-
#initialize(tasks_repo: Resource, file_path: Ruby::Pomodoro.tasks_file_path, editor: TTY::Editor) ⇒ Editor
constructor
A new instance of Editor.
-
#load ⇒ TrueClass
Load tasks form file.
-
#save ⇒ TrueClass
save list to disc.
Constructor Details
#initialize(tasks_repo: Resource, file_path: Ruby::Pomodoro.tasks_file_path, editor: TTY::Editor) ⇒ Editor
Returns a new instance of Editor.
10 11 12 13 14 |
# File 'lib/ruby/pomodoro/tasks/editor.rb', line 10 def initialize(tasks_repo: Resource, file_path: Ruby::Pomodoro.tasks_file_path, editor: TTY::Editor) @tasks_repo = tasks_repo @file_path = file_path @editor = editor end |
Instance Attribute Details
#editor ⇒ Object (readonly)
Returns the value of attribute editor.
5 6 7 |
# File 'lib/ruby/pomodoro/tasks/editor.rb', line 5 def editor @editor end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
5 6 7 |
# File 'lib/ruby/pomodoro/tasks/editor.rb', line 5 def file_path @file_path end |
#tasks_repo ⇒ Object (readonly)
Returns the value of attribute tasks_repo.
5 6 7 |
# File 'lib/ruby/pomodoro/tasks/editor.rb', line 5 def tasks_repo @tasks_repo end |
Instance Method Details
#edit ⇒ TrueClass
Open editor and save tasks from tmp file to task_repo
18 19 20 21 22 23 |
# File 'lib/ruby/pomodoro/tasks/editor.rb', line 18 def edit save editor.open(file_path) create_tasks true end |
#load ⇒ TrueClass
Load tasks form file
38 39 40 41 |
# File 'lib/ruby/pomodoro/tasks/editor.rb', line 38 def load create_tasks true end |
#save ⇒ TrueClass
save list to disc
27 28 29 30 31 32 33 34 |
# File 'lib/ruby/pomodoro/tasks/editor.rb', line 27 def save File.open(file_path, "w") do |f| if @tasks_repo.size > 0 f.puts(@tasks_repo.all.map {|task| print_task(task) }.join("\n")) end end true end |