Class: Tempo::Views::Formatters::Screen

Inherits:
Base
  • Object
show all
Defined in:
lib/tempo/views/formatters/screen.rb

Instance Method Summary collapse

Methods inherited from Base

#format_records, #format_records_container, #initialize, #report

Constructor Details

This class inherits a constructor from Tempo::Views::Formatters::Base

Instance Method Details

#active_indicator(project) ⇒ Object

spacer for project titles, active project marked with *



36
37
38
# File 'lib/tempo/views/formatters/screen.rb', line 36

def active_indicator(project)
  indicator = project.current ? "* " : "  "
end

#duration_block(record) ⇒ Object



27
28
29
30
31
# File 'lib/tempo/views/formatters/screen.rb', line 27

def duration_block(record)
  record.format do |d|
    puts "#{ d.hours.to_s }:#{ d.minutes.to_s.rjust(2, '0') }"
  end
end

#id_partial(id) ⇒ Object



54
55
56
# File 'lib/tempo/views/formatters/screen.rb', line 54

def id_partial(id)
  @options[:id] ? "[#{id}] ".rjust(6, ' ') : ""
end

#message_block(record) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tempo/views/formatters/screen.rb', line 15

def message_block(record)
  record.format do |m|
    case m.category
    when :error
      raise m.message
    when :info, :warning, :debug
      puts m.message
    end
    m.message
  end
end

#project_block(record) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/tempo/views/formatters/screen.rb', line 61

def project_block(record)

  record.format do |r|
    @options[:active] = @options.fetch( :active, false )
    record = r.title

    id = id_partial r.id
    active = @options[:active] ? active_indicator( r ) : ""
    depth = @options[:depth] ? "  " * r.depth : ""
    title = r.title
    view = "#{id}#{active}#{depth}#{title}"
    tags = @options[:tags] ? tag_partial( r.tags, view.length ) : ""
    view += tags
    puts view
  end
end

#tag_partial(tags, title_length) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/tempo/views/formatters/screen.rb', line 40

def tag_partial(tags, title_length)
  max_length = ViewRecords::Project.max_title_length
  max_length += ViewRecords::Project.max_depth * 2 if @options[:depth]
  max_length += 6 if @options[:id]
  max_length += 2 if @options[:active]
  spacer = [0, max_length - title_length].max
  view = "  " + ( " " * spacer )
  return  view + "tags: none" if tags.length < 1

  view += "tags: ["
  tags.each { |t| view += "#{t}, "}
  view[0..-3] + "]"
end

#timerecord_block(record) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/tempo/views/formatters/screen.rb', line 78

def timerecord_block(record)
  #require 'pry'; binding.pry
  record.format do |r|
    id = id_partial r.id
    running = r.running ? "*" : " "
    if @options[:bullet_report]
      view =  " * #{r.description}"
    else
      description = r.description.empty? ? "#{r.project}" : "#{r.project}: #{r.description}"
      view =  "#{id}#{r.start_time.strftime('%H:%M')} - #{r.end_time.strftime('%H:%M')}#{running} [#{r.duration.format}] #{description}"
    end
    puts view
  end
end