class JsonResume::Formatter

Attributes

hash[R]

Public Class Methods

new(hash) click to toggle source
# File lib/json_resume/formatter.rb, line 13
def initialize(hash)
  @hash = hash

  # recursively defined proc
  @hash_proc = proc do |k, v|
    v = k if v.nil? # HACK: to make it common for hash and array
    v.delete_if(&@hash_proc) if [Hash, Array].any? { |x| v.instance_of? x }
    v.empty?
  end
end

Public Instance Methods

add_last_marker_on_field(field_name) click to toggle source
# File lib/json_resume/formatter.rb, line 55
def add_last_marker_on_field(field_name)
  return if @hash['bio_data'][field_name].nil?
  @hash['bio_data'][field_name]['items'].each do |item|
    next if item['technology_used'].nil?
    item['technology_used']['tools'].map! { |x| { 'name' => x } }
    item['technology_used']['tools'][-1]['last'] = true
  end
end
add_last_marker_on_skills() click to toggle source
# File lib/json_resume/formatter.rb, line 38
def add_last_marker_on_skills
  return if @hash['bio_data']['skills'].nil?
  @hash['bio_data']['skills']['details'].each do |item|
    item['items'].map! { |x| { 'name' => x } }
    item['items'][-1]['last'] = true
  end
end
add_last_marker_on_stars() click to toggle source
# File lib/json_resume/formatter.rb, line 30
def add_last_marker_on_stars
  return if @hash['bio_data']['stars'].nil?
  @hash['bio_data']['stars'] = {
    'items' => @hash['bio_data']['stars'].map { |i| { 'name' => i } }
  }
  @hash['bio_data']['stars']['items'][-1]['last'] = true
end
add_last_marker_on_tools() click to toggle source
# File lib/json_resume/formatter.rb, line 46
def add_last_marker_on_tools
  return if @hash['bio_data']['other_projects'].nil?
  @hash['bio_data']['other_projects']['items'].each do |item|
    next if item['technology_used'].nil?
    item['technology_used']['tools'].map! { |x| { 'name' => x } }
    item['technology_used']['tools'][-1]['last'] = true
  end
end
add_linkedin_github_url() click to toggle source
# File lib/json_resume/formatter.rb, line 24
def add_linkedin_github_url
  @hash['raw_website'] = @hash['bio_data']['website'].sub(%r{^https?://}, '') if @hash['bio_data'] && @hash['bio_data']['website']
  @hash['linkedin_url'] = 'http://linkedin.com/in/' + @hash['linkedin_id'] if @hash['linkedin_id']
  @hash['github_url'] = 'http://github.com/' + @hash['github_id'] if @hash['github_id']
end
add_padding(course) click to toggle source
# File lib/json_resume/formatter.rb, line 92
def add_padding(course)
  return if @hash['bio_data'].nil? || @hash['bio_data'][course].nil?
  course_hash = @hash['bio_data'][course]
  course_hash << {} if course_hash.size.odd?
  @hash['bio_data'][course] = {
    'rows' => course_hash.each_slice(2).to_a.map { |i| { 'columns' => i } }
  }
end
cleanse() click to toggle source
# File lib/json_resume/formatter.rb, line 64
def cleanse
  @hash.delete_if(&@hash_proc)
  self
end
format() click to toggle source
# File lib/json_resume/formatter.rb, line 101
def format
  return if @hash['bio_data'].nil?

  cleanse

  format_to_output_type

  add_last_marker_on_stars

  add_last_marker_on_skills

  add_last_marker_on_field 'experience'
  add_last_marker_on_field 'other_projects'

  purge_gpa

  add_linkedin_github_url

  # make odd listed courses to even
  %w(grad_courses undergrad_courses).each do |course|
    add_padding(course)
  end

  self
end
format_string(_) click to toggle source
# File lib/json_resume/formatter.rb, line 79
def format_string(_)
  fail(NotImplementedError.new('format_string not impl in formatter'), '')
end
format_to_output_type() click to toggle source
# File lib/json_resume/formatter.rb, line 69
def format_to_output_type
  format_proc = proc do |k, v|
    v = k if v.nil?
    v.each { |x| format_proc.call(x) } if [Hash, Array].any? { |x| v.instance_of? x }
    format_string v if v.instance_of? String
  end
  @hash.each { |x| format_proc.call(x) }
  self
end
item_false?(item) click to toggle source
# File lib/json_resume/formatter.rb, line 83
def item_false?(item)
  item == false || item == 'false'
end
purge_gpa() click to toggle source
# File lib/json_resume/formatter.rb, line 87
def purge_gpa
  return if @hash['bio_data']['education'].nil?
  @hash['bio_data']['education'].delete('show_gpa') if item_false?(@hash['bio_data']['education']['show_gpa']) || @hash['bio_data']['education']['schools'].all? { |sch| sch['gpa'].nil? || sch['gpa'].empty? }
end