Module: EpilottoCurriculum

Includes:
Term::ANSIColor
Defined in:
lib/epilotto_curriculum.rb,
lib/epilotto_curriculum/version.rb

Constant Summary collapse

VERSION =
'0.3.0'

Instance Method Summary collapse

Instance Method Details

#build_from_yaml(yaml_file, width: 80, left_column_max_width_percent: 30) ⇒ Object



7
8
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
# File 'lib/epilotto_curriculum.rb', line 7

def build_from_yaml(yaml_file, width: 80, left_column_max_width_percent: 30)
  cv = YAML.load_file(yaml_file)
  name = cv.delete('name')
  updated_at = cv.delete('updated_at')
  about_me = cv.delete('about_me')
  left_column_max_width = (width * (left_column_max_width_percent/100.0)).round
  max_paragraph_width = cv.values.map(&:keys).flatten.max{|x,y| x.size <=> y.size}.size
  lc_w = (max_paragraph_width <= left_column_max_width ? max_paragraph_width : left_column_max_width) + 1
  rc_w = width - 3 - lc_w

  s = [draw_title(name, width, updated_at)]
  cv.each do |section, data|
    if section != :name
      s << draw_section(section, width) # lc_w - 1
      data.each do |left, right|
        l_lines = rpad(left, lc_w).split("\n")
        r_lines = lpad(right, rc_w).split("\n")
        i = 0
        while l_lines[i] || r_lines[i] do
          l_line = l_lines[i]
          l_line = ' ' * lc_w if !l_line || l_line =~ /\s*sep\d*$/
          s << "#{l_line} #{cyan}|#{reset} #{r_lines[i]}"
          i += 1
        end
      end
    end
  end
  s << draw_about_me(name, about_me, width)
  return s.join("\n")
end