class Spud::Lister
Constants
- NAMED_HEADER
- ORDERED_HEADER
- SOURCES_HEADER
- TASKS_HEADER
Public Class Methods
new(tasks)
click to toggle source
# File lib/spud/lister.rb, line 16 def initialize(tasks) @tasks = tasks end
Public Instance Methods
list_tasks!()
click to toggle source
# File lib/spud/lister.rb, line 21 def list_tasks! builder = StringIO.new if show_headers? builder.write TASKS_HEADER.ljust(max_task_length) if show_ordered_args? builder.write ' ' builder.write ORDERED_HEADER.ljust(max_ordered_string_length) end if show_named_args? builder.write ' ' builder.write NAMED_HEADER.ljust(max_named_string_length) end if show_sources? builder.write ' ' builder.write SOURCES_HEADER end builder.write "\n" end @tasks.each do |task| builder.write task.name.ljust(max_task_length) if show_ordered_args? builder.write ' ' builder.write task.args.ordered.join(' ').ljust(max_ordered_string_length) end if show_named_args? builder.write ' ' builder.write task.args.named.join(' ').ljust(max_named_string_length) end if show_sources? builder.write ' ' builder.write task.source end builder.write "\n" end puts builder.string end
Private Instance Methods
max_named_string_length()
click to toggle source
# File lib/spud/lister.rb, line 99 def max_named_string_length @max_named_string_length ||= @tasks .map { |task| task.args.named.join(' ') } .map(&:length) .tap { |lengths| lengths.push(NAMED_HEADER.length) if show_headers? } .max end
max_ordered_string_length()
click to toggle source
# File lib/spud/lister.rb, line 85 def max_ordered_string_length @max_ordered_string_length ||= @tasks .map { |task| task.args.ordered.join(' ') } .map(&:length) .tap { |lengths| lengths.push(ORDERED_HEADER.length) if show_headers? } .max end
max_task_length()
click to toggle source
# File lib/spud/lister.rb, line 77 def max_task_length @max_task_length ||= @tasks .map { |task| task.name.length } .tap { |lengths| lengths.push(TASKS_HEADER.length) if show_headers? } .max end
show_headers?()
click to toggle source
# File lib/spud/lister.rb, line 72 def show_headers? @show_headers ||= show_ordered_args? || show_named_args? || show_sources? end
show_named_args?()
click to toggle source
# File lib/spud/lister.rb, line 108 def show_named_args? @show_named_args ||= @tasks.any? { |task| task.args.any_named? } end
show_ordered_args?()
click to toggle source
# File lib/spud/lister.rb, line 94 def show_ordered_args? @show_ordered_args ||= @tasks.any? { |task| task.args.any_ordered? } end
show_sources?()
click to toggle source
# File lib/spud/lister.rb, line 113 def show_sources? sources.length > 1 end
sources()
click to toggle source
# File lib/spud/lister.rb, line 118 def sources @filenames ||= @tasks.map(&:source).uniq end