class CV

Attributes

is_pdf[RW]

Public Class Methods

new(file_path) click to toggle source
# File lib/yaml-cv.rb, line 43
    def initialize(file_path)
    @file_path = file_path
            @cv = YAML.load_file(file_path)

    if  @cv["contact"]
        @cv["contact"] = @cv["contact"].map { |c|
            c["icon_svg"] = icon(c["icon"])
            c
        }
    end
end

Public Instance Methods

contact() click to toggle source
# File lib/yaml-cv.rb, line 127
def contact
    # split into a 2-column table
    contact_table = Array.new(3){Array.new(2)}

    i = 0
    while i < @cv["contact"].length()

        row = i % 3
        col = 1 - (i / 3)
        contact_table[row][col] = @cv["contact"][i]

        i = i + 1
    end
    contact_table
end
css() click to toggle source
# File lib/yaml-cv.rb, line 115
def css
    load_asset("style.css")
end
details() click to toggle source
# File lib/yaml-cv.rb, line 55
def details
    @cv["details"]
end
enable_pdf(enable = true) click to toggle source
# File lib/yaml-cv.rb, line 123
def enable_pdf(enable = true)
    @is_pdf = true
end
format_subsections(subsections) click to toggle source
# File lib/yaml-cv.rb, line 147
def format_subsections(subsections)
    if !subsections
        return
    end

    subsections.map { |e|
        if e["from"]
            e["from"] = format_period e["from"]
        end
        if e["to"]
            e["to"] = format_period e["to"]
        end

        if e["logo"]
            e["logo_img"] = read_image e["logo"]
        end

        e
    }
end
full_name() click to toggle source
# File lib/yaml-cv.rb, line 111
    def full_name
            details["last_name"] + " " + details["first_name"]
end
has_profile() click to toggle source
# File lib/yaml-cv.rb, line 63
def has_profile
    @cv.key?("profile")
end
has_skills() click to toggle source
# File lib/yaml-cv.rb, line 88
def has_skills
    @cv.key?("skills")
end
has_technical() click to toggle source
# File lib/yaml-cv.rb, line 96
def has_technical
    @cv.key?("technical")
end
icon(name) click to toggle source
# File lib/yaml-cv.rb, line 143
def icon(name)
    load_asset("icons/#{name.strip}.svg")
end
is_windows() click to toggle source
# File lib/yaml-cv.rb, line 210
def is_windows
    RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
end
pdf_css() click to toggle source
# File lib/yaml-cv.rb, line 119
def pdf_css
    load_asset("pdf.css")
end
profile() click to toggle source
# File lib/yaml-cv.rb, line 59
def profile
    @cv["profile"]
end
read_image(img_path) click to toggle source
# File lib/yaml-cv.rb, line 168
def read_image(img_path)
    file_path = File.join(File.dirname(@file_path), img_path)
    file = File.open(file_path, "rb")
    data = file.read
    Base64.strict_encode64(data)
end
render() click to toggle source
Calls superclass method
# File lib/yaml-cv.rb, line 175
def render
    template = load_asset("cv.mustache")
    super(template)
end
sections() click to toggle source
# File lib/yaml-cv.rb, line 100
def sections
    if !@cv["sections"]
        return
    end

    @cv["sections"].map { |s|
        s["items"] = format_subsections s["items"]
        s
    }
end
skills() click to toggle source
# File lib/yaml-cv.rb, line 67
def skills
    # split into an n-column table
    nskills = @cv["skills"]["fields"].length()
    ncols = @cv["skills"]["columns"]
    nrows = (nskills.to_f / ncols).ceil

    skills_table = Array.new(nrows){Array.new(ncols)}

    i = 0
    while i < nskills

        col = i % ncols
        row = i / ncols

        skills_table[row][col] = @cv["skills"]["fields"][i]

        i = i + 1
    end
    skills_table
end
technical() click to toggle source
# File lib/yaml-cv.rb, line 92
def technical
    @cv["technical"]
end
write_html(file_path) click to toggle source
# File lib/yaml-cv.rb, line 180
def write_html(file_path)
    html = render
    File.open(file_path, 'w') { |file| file.write(html) }
end
write_pdf(file_path) click to toggle source
# File lib/yaml-cv.rb, line 185
def write_pdf(file_path)

    if is_windows
        temp_file_name = file_path + ".html"

        temp_file = File.open(temp_file_name, "w")
        temp_file << render
        temp_file.flush
        temp_file.close

        system("wkhtmltopdf.exe #{temp_file.path} #{file_path}")

        File.delete(temp_file_name)
    else
        temp_file = Tempfile.new(["cv", ".html"])
        temp_file << render
        temp_file.flush

        system("wkhtmltopdf #{temp_file.path} #{file_path}")

        temp_file.close
    end

end