Module: MultiformatCV

Defined in:
lib/multiformatcv.rb,
lib/multiformatcv/version.rb

Defined Under Namespace

Classes: Contact, Job, Personal, Project, Resume

Constant Summary collapse

YML_FILES =

YAML files that will be read from the specified directory

%w( contact jobs personal )
VERSION =
"0.0.3"

Class Method Summary collapse

Class Method Details

.generate(opts = {}) ⇒ String

Parse yaml files located at data directory

Parameters:

  • opts (Hash) (defaults to: {})

    Options to specify format and templates source

Options Hash (opts):

  • :data_dir (String)

    Directory where the YAML files are located.

  • :format (Symbol)

    One of [ :html, :tex ]

  • :templates (String)

    Directory where templates are located, expected template files are ‘cv.#{ format }.erb`

Returns:

  • (String)

    Evaluated Erubi::Engine’s source

See Also:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/multiformatcv.rb', line 20

def self.generate(opts = {})
  opts['format'] ||= 'html'
  opts['data_dir'] ||= 'data'
  opts['templates'] ||= File.expand_path("../multiformatcv/templates", __FILE__)
  opts['output'] ||= STDOUT

  template = File.read("#{ opts['templates'] }/cv.#{ opts['format'] }.erb")
  resume = Resume.new
  yml = nil

  YML_FILES.each do |f|
    yml = YAML.load_file("#{ opts['data_dir'] }/#{ f }.yml")
    if yml then
      resume.send("add_#{ f }", yml[f])
    end
  end

  result = eval Erubi::Engine.new(template).src
  if opts['output'] == STDOUT then
    puts result
  else
    File.open(opts['output'], "w") { |f| f.write(result) }
  end
end