Class: Plansheet::WeeklyLaTeXSheet

Inherits:
Object
  • Object
show all
Includes:
LaTeXMixins, TimeUtils
Defined in:
lib/plansheet/sheet/weekly.rb

Constant Summary collapse

MINIPAGE_SIZE =
"6cm".freeze
DEFAULT_PROJECT_TIME_ESTIMATE_MIN =
120

Constants included from LaTeXMixins

LaTeXMixins::HARD_NL, LaTeXMixins::SQUARE

Instance Method Summary collapse

Methods included from TimeUtils

#build_time_duration, #parse_date_duration, #parse_time_duration

Methods included from LaTeXMixins

#checkbox_item, #config_file_sanity_check, #itemize_tightlist, #itemline, #minipage, #sanitize_string, #sheet_header, #vbox, #vspace, #writein_line

Constructor Details

#initialize(output_file, projects, config) ⇒ WeeklyLaTeXSheet

Returns a new instance of WeeklyLaTeXSheet.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/plansheet/sheet/weekly.rb', line 9

def initialize(output_file, projects, config)
  @config = config || {}
  config_file_sanity_check({
                             "namespaces" => Hash,
                             "tags" => Hash
                           })

  @external_commits = projects.select(&:externals) || []
  @projects = projects # TODO: remove finished?
  str = sheet_header
  str << document do
    [
      week_line,
      [
        event_writeins,
        past_due,
        upcoming_due
      ].compact.join,
      # Since the following are a lot more volatile in minipage length,
      # sort by newline so more fits on the page
      [
        external_commits,
        works_in_progress,
        tag_minipages,
        namespace_minipages,
        recurring_defer
      ].flatten.compact.sort_by { |x| x.count("\n") }.join
    ].flatten.join
  end
  puts "Writing to #{output_file}"
  File.write(output_file, str)
end

Instance Method Details

#event_writeinsObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/plansheet/sheet/weekly.rb', line 80

def event_writeins
  minipage(MINIPAGE_SIZE) do
    "Events:\n#{
      itemize_tightlist do
        7.times.map do |n|
          itemline(
            writein_line("4cm"),
            opt: (Date.today + n).strftime("%a %m-%d")
          )
        end.join.concat("\n")
      end
    }"
  end
end

#external_commitsObject



76
77
78
# File 'lib/plansheet/sheet/weekly.rb', line 76

def external_commits
  project_minipage("Externals", @external_commits) unless @external_commits&.empty?
end

#namespace_minipagesObject



42
43
44
45
46
47
# File 'lib/plansheet/sheet/weekly.rb', line 42

def namespace_minipages
  @config["namespaces"].map do |namespace, limit|
    projects = @projects.select { |x| x.namespace == namespace }
    project_minipage namespace, projects_in_time(projects, limit)
  end&.join
end

#past_dueObject



61
62
63
64
# File 'lib/plansheet/sheet/weekly.rb', line 61

def past_due
  projects = @projects.select { |x| x.due ? x.due < Date.today : false }
  project_minipage "Past due", projects if projects
end

#pretty_tag_name(tag) ⇒ Object



95
96
97
# File 'lib/plansheet/sheet/weekly.rb', line 95

def pretty_tag_name(tag)
  tag.capitalize.gsub("_", " ")
end

#project_minipage(thing, projects = []) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/plansheet/sheet/weekly.rb', line 99

def project_minipage(thing, projects = [])
  unless projects&.empty?
    minipage(MINIPAGE_SIZE) do
      "#{thing}:
    #{itemize_tightlist do
        projects&.map do |x|
          itemline("#{x.name} #{x&.time_estimate}", opt: SQUARE)
        end&.join("\n")
      end
    }"
    end
  end
end

#projects_in_time(projects, time) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/plansheet/sheet/weekly.rb', line 114

def projects_in_time(projects, time)
  projects ||= []
  t = parse_time_duration(time)
  p = []
  projects.each do |proj|
    e = proj&.time_estimate ? parse_time_duration(proj.time_estimate) : DEFAULT_PROJECT_TIME_ESTIMATE_MIN
    if e <= t
      p.append proj
      t -= e
    end
  end
  p
end

#recurring_deferObject



66
67
68
69
# File 'lib/plansheet/sheet/weekly.rb', line 66

def recurring_defer
  projects = @projects.select { |x| x.last_for ? x.last_for_deferral < Date.today + 8 : false }
  project_minipage "Recurring defer", projects if projects
end

#tag_minipagesObject



49
50
51
52
53
54
# File 'lib/plansheet/sheet/weekly.rb', line 49

def tag_minipages
  @config["tags"].map do |tag, limit|
    projects = @projects.select { |x| x&.tags&.any?(tag) }
    project_minipage pretty_tag_name(tag), projects_in_time(projects, limit)
  end&.join
end

#upcoming_dueObject



71
72
73
74
# File 'lib/plansheet/sheet/weekly.rb', line 71

def upcoming_due
  projects = @projects.select { |x| x.due ? (x.due >= Date.today && x.due < Date.today + 8) : false }
  project_minipage "Upcoming due", projects if projects
end

#week_lineObject



128
129
130
# File 'lib/plansheet/sheet/weekly.rb', line 128

def week_line
  "For the next week: #{Date.today} - #{Date.today + 7}\n\n"
end

#works_in_progressObject



56
57
58
59
# File 'lib/plansheet/sheet/weekly.rb', line 56

def works_in_progress
  projects = @projects.select(&:wip?)
  project_minipage "Works in progress", projects if projects
end