Sha256: a8e3dd629257cad5f99373c05e54b40a43f5fda3621c7d18b1badc79b1a38dd6
Contents?: true
Size: 1.83 KB
Versions: 1
Compression:
Stored size: 1.83 KB
Contents
module Todo class Presenter 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 #LIST PRESENTATION 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 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 #TASK PRESENTATION 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 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 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 end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
2do-0.0.2 | lib/todo/presenter.rb |