Class: CliTasks::Viewer

Inherits:
Object
  • Object
show all
Defined in:
lib/clitasks/viewer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Viewer

Returns a new instance of Viewer.



3
4
5
6
7
8
9
10
# File 'lib/clitasks/viewer.rb', line 3

def initialize(*args)
  @files = args
  if args.any?
    Runner.run *args
  else
    Runner.run 'stories/index/*'
  end
end

Class Method Details



12
13
14
# File 'lib/clitasks/viewer.rb', line 12

def self.print(*args)
  new(*args).print
end

Instance Method Details

#headerObject



26
27
28
# File 'lib/clitasks/viewer.rb', line 26

def header
  sprintf(" %-10s | %-20s | %-6s | %-60s | %-s", :status, :id, :points, :name, :tags)
end


16
17
18
19
20
21
22
23
24
# File 'lib/clitasks/viewer.rb', line 16

def print
  puts header

  puts stories.sort_by{|s| s.name }.inject({}){|hash,s|
    hash.merge( s.status => hash.fetch(s.status, []) << s )
  }.map{|status,group|
    [separator] + group.map{|s| story(s) }
  }
end

#separatorObject



30
31
32
# File 'lib/clitasks/viewer.rb', line 30

def separator
  sprintf(" %-10s | %-20s | %-6s | %-60s | %-s", ?-*10, ?-*20, ?-*6, ?-*60, ?-*20)
end

#storiesObject



38
39
40
# File 'lib/clitasks/viewer.rb', line 38

def stories
  @stories ||= World.instance.stories
end

#story(s) ⇒ Object



34
35
36
# File 'lib/clitasks/viewer.rb', line 34

def story(s)
  sprintf(" %-10s | %-20s | %-6s | %-60s | %-s", s.status, s.id, ?* * s.points.to_i, s.name.slice(0,60), Array(s.tags).join(', '))
end