Class: ResumeGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/resume_generator.rb

Constant Summary collapse

ValueError =
Class.new(StandardError)
POSTAMBLE =
<<~POSTAMBLE.freeze
    </div>
    </body>
    <script>
  #{File.read(File.expand_path('../assets/reload.js', __dir__))}
    </script>
    </html>
POSTAMBLE
CHROME_GUESSES_MACOS =
[
  '/Applications/Chromium.app/Contents/MacOS/Chromium',
  '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary',
  '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
].freeze
LINUX_CHROME_DIRS =
[
  '/usr/local/sbin',
  '/usr/local/bin',
  '/usr/sbin',
  '/usr/bin',
  '/sbin',
  '/bin',
  '/opt/google/chrome',
  "/etc/profiles/per-user/#{ENV['USER']}/bin" # NixOS
].freeze
LINUX_CHROME_EXECUTABLES =
%w[google-chrome chrome chromium chromium-browser].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ ResumeGenerator

Returns a new instance of ResumeGenerator.



40
41
42
43
# File 'lib/resume_generator.rb', line 40

def initialize(opts)
  @opts = opts
  @opts.chrome_path = guess_chrome_path if @opts.pdf && @opts.chrome_path.nil?
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



8
9
10
# File 'lib/resume_generator.rb', line 8

def opts
  @opts
end

Instance Method Details

#generate_templateObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/resume_generator.rb', line 59

def generate_template
  curr = Pathname.new(__FILE__).dirname
  if @opts.generate_md
    relative = Pathname.new('../assets/sample-resume.md')
    template = File.expand_path(relative, curr)
    FileUtils.copy_file(template, "#{@opts.input}.md")
  end

  return unless @opts.generate_css

  relative = Pathname.new('../assets/defaults.css')
  template = File.expand_path(relative, curr)
  FileUtils.copy_file(template, "#{@opts.input}.css")
end

#valid_input?Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
# File 'lib/resume_generator.rb', line 51

def valid_input?
  puts "Input file: #{@opts.input}"
  return if File.exist?(@opts.input)

  puts "Resume not found at #{@opts.input}"
  exit
end

#writeObject



45
46
47
48
49
# File 'lib/resume_generator.rb', line 45

def write
  valid_input?
  write_html
  write_pdf
end