Skip to content

Commit

Permalink
Handle more reeks
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfioravanti committed Mar 21, 2017
1 parent 01ee31c commit 3e239b1
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 36 deletions.
24 changes: 20 additions & 4 deletions .reek
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
DataClump:
# NOTE: The Prawn API and the functional nature of how the resume is
# generated tends to generate what OO would consider data clumps
exclude:
- "Resume::PDF::Entry::Content"
FeatureEnvy:
# NOTE: Many of the exclusions here are due to reek not being able to see
# `module_function` methods aren't instance methods that need to refer to a
# `self`.
exclude:
- "Resume::PDF::EmploymentHistory#footer"
- "Resume::PDF::Entry::Content#details"
- "Resume::PDF::Entry::Header#formatted_text_box_header"
- "Resume::PDF::Entry::Heading#generate"
- "Resume::PDF::ImageLink#generate"
- "Resume::PDF::TechnicalSkills#generate_table"
IrresponsibleModule:
enabled: false
NestedIterators:
# NOTE: some of the exclusions are here because reek considers
# passing a block to File.open an iterator, which I do not
exclude:
- "Resume::PDF::Document#self.generate"
- "Resume::PDF::Entry::Header#formatted_text_box_header"
- "Resume::PDF::Entry::Header#formatted_text_header"
- "Resume::CLI::FileFetcher#remote_file"
- "Resume::CLI::FontDownloader#self.extract_fonts"
- "Resume::PDF::Document#self.generate"
- "Resume::PDF::Entry::Header#self.formatted_text_box_header"
- "Resume::PDF::Entry::Header#self.formatted_text_header"
TooManyStatements:
exclude:
- "Resume::CLI::Application#self.start"
- "Resume::CLI::ArgumentParser#self.parser"
- "Resume::CLI::FontDownloader#fonts_successfully_downloaded?"
- "Resume::CLI::FontDownloader#self.extract_fonts"
- "Resume::PDF::EmploymentHistory#self.generate"
- "Resume::PDF::Manifest#self.process"
- "Resume::PDF::Manifest#process"
- "Resume::PDF::SocialMediaLogoSet#self.generate_logo_for"
- "Resume::PDF::TechnicalSkills#self.generate"

21 changes: 17 additions & 4 deletions lib/resume/pdf/employment_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,26 @@ module EmploymentHistory

def generate(pdf, employment_history)
Entry::Heading.generate(pdf, employment_history[:heading])
content = employment_history[:content]
content[:entries].values.each do |entry|
entries, bottom_padding, horizontal_rule_colour =
employment_history[:content].values_at(
:entries, :bottom_padding, :horizontal_rule_colour
)
generate_content(entries)
footer(pdf, bottom_padding, horizontal_rule_colour)
end

def generate_content(entries)
entries.values.each do |entry|
Entry::Content.generate(pdf, entry)
end
pdf.move_down(content[:bottom_padding])
pdf.stroke_horizontal_rule { color content[:horizontal_rule_colour] }
end
private_class_method :generate_content

def footer(pdf, bottom_padding, horizontal_rule_colour)
pdf.move_down(bottom_padding)
pdf.stroke_horizontal_rule { color(horizontal_rule_colour) }
end
private_class_method :footer
end
end
end
21 changes: 10 additions & 11 deletions lib/resume/pdf/entry/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,31 @@ module Content
module_function

def generate(pdf, entry)
pdf.move_down(entry[:top_padding])
top_padding, logo, summary =
entry.values_at(:top_padding, :logo, :summary)
pdf.move_down(top_padding)
Header.generate(pdf, entry)
CompanyLogo.generate(pdf, entry[:logo])
details(pdf, entry) if entry.key?(:summary)
CompanyLogo.generate(pdf, logo)
details(pdf, entry) if summary
end

def details(pdf, entry)
pdf.move_down(entry.dig(:summary, :top_padding))
pdf.text(entry.dig(:summary, :text), inline_format: true)
top_padding, text = entry[:summary].values_at(:top_padding, :text)
pdf.move_down(top_padding)
pdf.text(text, inline_format: true)
profile(pdf, entry)
end
private_class_method :details

def profile(pdf, entry)
return unless (job_content = entry[:profile])
cell_style = entry[:cell_style]
borders, height = entry[:cell_style].values_at(:borders, :height)
table_data =
job_content.reduce([]) do |content, responsibility|
content << ["-", responsibility]
end
pdf.table(
table_data,
cell_style: {
borders: cell_style[:borders],
height: cell_style[:height]
}
table_data, cell_style: { borders: borders, height: height }
)
end
private_class_method :profile
Expand Down
19 changes: 12 additions & 7 deletions lib/resume/pdf/entry/header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@ def generate(pdf, entry)
# Different rendering behaviour needed depending on whether
# the header is being drawn from left to right on the page
# or specifically placed at a location on the x-axis
header_sections = [
[entry[:position]],
[entry[:organisation]],
[entry[:period], entry[:location]]
]
entry_header_sections = header_sections(entry)
if (x_position = entry[:at_x_position])
formatted_text_box_header(header_sections, pdf, x_position)
formatted_text_box_header(entry_header_sections, pdf, x_position)
else
formatted_text_header(header_sections, pdf)
formatted_text_header(entry_header_sections, pdf)
end
end

Expand All @@ -40,6 +36,15 @@ def formatted_text_header(header_sections, pdf)
end
private_class_method :formatted_text_header

def header_sections(entry)
[
[entry[:position]],
[entry[:organisation]],
[entry[:period], entry[:location]]
]
end
private_class_method :header_sections

def properties_for(section)
{
text: section[:text],
Expand Down
6 changes: 4 additions & 2 deletions lib/resume/pdf/image_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ module ImageLink
module_function

def generate(pdf, logo)
pdf.image(logo[:image], fit: logo[:fit], align: logo[:align])
pdf.move_up logo[:link_overlay_start]
image, fit, align, link_overlay_start =
logo.values_at(:image, :fit, :align, :link_overlay_start)
pdf.image(image, fit: fit, align: align)
pdf.move_up(link_overlay_start)
transparent_link(pdf, logo)
end

Expand Down
12 changes: 8 additions & 4 deletions lib/resume/pdf/social_media_logo_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ module SocialMediaLogoSet
module_function

def generate(pdf, logo_set)
pdf.move_down(logo_set[:top_padding])
top_padding, horizontal_rule_colour =
logo_set.values_at(
:top_padding, :bottom_padding, :horizontal_rule_colour
)
pdf.move_down(top_padding)
generate_logos(pdf, logo_set)
pdf.move_down(logo_set[:bottom_padding])
pdf.stroke_horizontal_rule { color logo_set[:horizontal_rule_colour] }
pdf.stroke_horizontal_rule { color(horizontal_rule_colour) }
end

def generate_logos(pdf, logo_set)
logos = entire_logo_properties(logo_set)
generate_logo_for(logos.first, pdf, logo_set)
logos[1..-1].each do |logo|
pdf.move_up(logo_set[:padded_logo_height])
generate_logo_for(logo, pdf, logo_set)
end
pdf.move_down(logo_set[:bottom_padding])
end
private_class_method :generate_logos

Expand All @@ -30,6 +33,7 @@ def entire_logo_properties(logo_set)
private_class_method :entire_logo_properties

def generate_logo_for(logo, pdf, logo_set)
pdf.move_up(logo_set[:padded_logo_height])
x_position = logo_set[:x_position]
pdf.bounding_box([x_position, pdf.cursor], width: logo[:width]) do
ImageLink.generate(pdf, logo)
Expand Down
14 changes: 10 additions & 4 deletions lib/resume/pdf/technical_skills.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ module TechnicalSkills
module_function

def generate(pdf, technical_skills)
Entry::Heading.generate(pdf, technical_skills[:heading])
content = technical_skills[:content]
pdf.move_down(content[:top_padding])
pdf.table(technical_skills(content), content[:properties])
heading, content = technical_skills.values_at(:heading, :content)
Entry::Heading.generate(pdf, heading)
generate_table(pdf, content)
end

def generate_table(pdf, content)
top_padding, properties = content.values_at(:top_padding, :properties)
pdf.move_down(top_padding)
pdf.table(technical_skills(content), properties)
end
private_class_method :generate_table

def technical_skills(content)
content[:skills].reduce([]) do |entries, (title, entry)|
entries << [title, entry]
Expand Down

0 comments on commit 3e239b1

Please sign in to comment.