Class: ListTask

Inherits:
Object
  • Object
show all
Defined in:
lib/tasks/list_task.rb

Instance Method Summary collapse

Constructor Details

#initialize(format_string = "%s") ⇒ ListTask

Returns a new instance of ListTask.



3
4
5
# File 'lib/tasks/list_task.rb', line 3

def initialize(format_string = "%s")
  @format_string = format_string
end

Instance Method Details

#get_detail(paths) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tasks/list_task.rb', line 19

def get_detail(paths)
  detail = ""
  limit = [paths.length - 1, 14].min
  (0..limit).each do |i|
    path = paths[i]
    detail += (@format_string % path)
    detail += "\n"
  end
  if limit < paths.length - 1
    detail += " - Plus #{(paths.length - 1) - limit} more files."
  end

  return detail
end

#run(files) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/tasks/list_task.rb', line 7

def run(files)
  all_files = files[:all]
  mofified_files = files[:filtered]

  return {
      :state => :success,
      :title => 'List',
      :first => mofified_files.length == 1 ? mofified_files[0] : '%s files.' % mofified_files.length,
      :detail => get_detail(mofified_files)
    }
end