class Todo::Presenter
Public Instance Methods
present(item:,**options)
click to toggle source
# File lib/todo/presenter.rb, line 4 def present(item:,**options) @presentable = item @level = options[:level] ||= :basic @info = options.fetch(:info) @exclude = options[:exclude] print send("render_#{@presentable.type}_#{@info}_#{@level}", @presentable) end
Private Instance Methods
presentable_tasks()
click to toggle source
# File lib/todo/presenter.rb, line 64 def presentable_tasks @data = @presentable.to_h[:tasks] @data = @data.select { |item| item[:finished] == false } if @exclude == :finished @data = @data.select { |item| item[:finished] == true } if @exclude == :open @data end
render_list_lists_basic(presentable)
click to toggle source
LIST PRESENTATION
# File lib/todo/presenter.rb, line 15 def render_list_lists_basic(presentable) lists = presentable.to_h[:lists] output = "Lists\n" lists.each_with_index do |t, i| order = i + 1 output << "#{order}. #{t[:name]}\n" end output end
render_list_lists_verbose(presentable)
click to toggle source
# File lib/todo/presenter.rb, line 25 def render_list_lists_verbose(presentable) lists = presentable.to_h[:lists] output = "Lists\n" lists.each_with_index do |t, i| order = i + 1 output << "#{order}. #{t[:name]} | tasks: #{t[:tasks].count}\n" end output end
render_list_tasks_basic(presentable)
click to toggle source
TASK PRESENTATION
# File lib/todo/presenter.rb, line 36 def render_list_tasks_basic(presentable) tasks = presentable_tasks output = "Tasks\n" tasks.each_with_index do |t,i| order = i + 1 output << "#{order}. #{t[:name]}\n" end output end
render_list_tasks_verbose(presentable)
click to toggle source
# File lib/todo/presenter.rb, line 46 def render_list_tasks_verbose(presentable) tasks = presentable_tasks output = "Tasks\n" tasks.each_with_index do |t, i| order = i + 1 substring = "#{order}. #{t.delete(:name)} " substring << "| ---- FINISHED ----" if t.delete(:finished) t.each do |key, value| if value substring << "| #{key}: #{value}" end end substring << "\n" output << substring end output end