lib/epilotto_curriculum.rb in epilotto_curriculum-0.2.0 vs lib/epilotto_curriculum.rb in epilotto_curriculum-0.2.1
- old
+ new
@@ -5,16 +5,17 @@
include Term::ANSIColor
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')
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)]
+ 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")
@@ -27,11 +28,10 @@
i += 1
end
end
end
end
- s << ''
return s.join("\n")
end
private
@@ -72,13 +72,14 @@
r << line.rjust(width)
end
return r.join("\n")
end
- def draw_title(name, width)
+ def draw_title(name, width, updated_at = nil)
title = "#{name.upcase}'s curriculum vitæ"
- s = "#{title} (last update 1 March 2017)".center(width)
- s.gsub!(title, bold(red(title)))
+ s = title
+ s = "#{title} (last update #{updated_at})" if updated_at
+ s = s.center(width).gsub(title, bold(red(title)))
return "\n#{s}\n"
end
def draw_section(s, width)
lw = width - s.size - 4