Class: Ditz::ScreenView

Inherits:
View show all
Defined in:
lib/ditz/views.rb,
lib/ditz/plugins/git.rb,
lib/ditz/plugins/mercurial.rb,
lib/ditz/plugins/issue-claiming.rb,
lib/ditz/plugins/issue-labeling.rb,
lib/ditz/plugins/issue-timetracker.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from View

add_to_view, view_additions_for

Constructor Details

#initialize(project, config, device = $stdout) ⇒ ScreenView

Returns a new instance of ScreenView.



8
9
10
11
# File 'lib/ditz/views.rb', line 8

def initialize project, config, device=$stdout
  @device = device
  @config = config
end

Class Method Details

.get_time_spent(issue) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/ditz/plugins/issue-timetracker.rb', line 38

def self.get_time_spent(issue)
  if issue.status == :paused
    issue.time_spent
  elsif issue.time_spent && issue.mark_time
    issue.time_spent + (Time.now - issue.mark_time)
  else
    0
  end
end

.humanize(seconds) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/ditz/plugins/issue-timetracker.rb', line 29

def self.humanize(seconds)
  result = ""
  %w[year month day hour minute second].zip([3600*24*30*365, 3600*24*30, 3600*24, 3600, 60, 1]).inject(seconds) do |seconds, item|
    num, seconds = modulo(seconds, item[1])
    result << "#{item[0].pluralize(num)} " unless num == 0
    seconds
  end
  result
end

.modulo(seconds, quotient) ⇒ Object



26
27
28
# File 'lib/ditz/plugins/issue-timetracker.rb', line 26

def self.modulo(seconds, quotient)
  result, remainder = seconds / quotient, seconds % quotient
end

Instance Method Details

#render_issue(issue) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ditz/views.rb', line 22

def render_issue issue
  status = case issue.status
  when :closed
    "#{issue.status_string}: #{issue.disposition_string}"
  else
    issue.status_string
  end
  desc = if issue.desc.size < 80 - "Description: ".length
    issue.desc
  else
    "\n" + issue.desc.gsub(/^/, "  ") + "\n"
  end
  run_pager @config
  @device.puts <<EOS
#{"Issue #{issue.name}".underline}
    Title: #{issue.title}
Description: #{desc}
     Type: #{issue.type}
   Status: #{status}
  Creator: #{issue.reporter}
      Age: #{issue.creation_time.ago}
  Release: #{issue.release}
 References: #{issue.references.listify "  "}
 Identifier: #{issue.id}
EOS

  self.class.view_additions_for(:issue_summary).each { |b| @device.print(b[issue, @config] || next) }
  puts
  self.class.view_additions_for(:issue_details).each { |b| @device.print(b[issue, @config] || next)  }

  @device.puts <<EOS
Event log:
#{format_log_events issue.log_events}
EOS
end