Class: Resume::Serializer
- Inherits:
-
Object
- Object
- Resume::Serializer
- Defined in:
- lib/serializer.rb
Overview
Serializes a resume to/from YAML
Instance Attribute Summary collapse
-
#core_prefix ⇒ Object
Returns the value of attribute core_prefix.
-
#core_to_use ⇒ Object
Returns the value of attribute core_to_use.
-
#education_prefix ⇒ Object
Returns the value of attribute education_prefix.
-
#experience_prefix ⇒ Object
Returns the value of attribute experience_prefix.
-
#filter_file ⇒ Object
Returns the value of attribute filter_file.
-
#references_prefix ⇒ Object
Returns the value of attribute references_prefix.
-
#samples_prefix ⇒ Object
Returns the value of attribute samples_prefix.
-
#skills_prefix ⇒ Object
Returns the value of attribute skills_prefix.
Instance Method Summary collapse
- #dump(dir, base_name, items) ⇒ Object
-
#initialize ⇒ Serializer
constructor
A new instance of Serializer.
-
#load(dir) ⇒ Object
Loads the resume artifacts from the given directory.
- #read(dir, base_name, allow_prefix_only = false) ⇒ Object
- #read_cores(dir, base_name) ⇒ Object
-
#store(dir, resume) ⇒ Object
Stores the resume artifacts to the given directory.
Constructor Details
#initialize ⇒ Serializer
Returns a new instance of Serializer.
19 20 21 22 23 24 25 26 |
# File 'lib/serializer.rb', line 19 def initialize @experience_prefix='experience' @education_prefix='education' @references_prefix='references' @samples_prefix='samples' @core_prefix='resume' @skills_prefix='skills' end |
Instance Attribute Details
#core_prefix ⇒ Object
Returns the value of attribute core_prefix.
14 15 16 |
# File 'lib/serializer.rb', line 14 def core_prefix @core_prefix end |
#core_to_use ⇒ Object
Returns the value of attribute core_to_use.
16 17 18 |
# File 'lib/serializer.rb', line 16 def core_to_use @core_to_use end |
#education_prefix ⇒ Object
Returns the value of attribute education_prefix.
11 12 13 |
# File 'lib/serializer.rb', line 11 def education_prefix @education_prefix end |
#experience_prefix ⇒ Object
Returns the value of attribute experience_prefix.
10 11 12 |
# File 'lib/serializer.rb', line 10 def experience_prefix @experience_prefix end |
#filter_file ⇒ Object
Returns the value of attribute filter_file.
17 18 19 |
# File 'lib/serializer.rb', line 17 def filter_file @filter_file end |
#references_prefix ⇒ Object
Returns the value of attribute references_prefix.
12 13 14 |
# File 'lib/serializer.rb', line 12 def references_prefix @references_prefix end |
#samples_prefix ⇒ Object
Returns the value of attribute samples_prefix.
13 14 15 |
# File 'lib/serializer.rb', line 13 def samples_prefix @samples_prefix end |
#skills_prefix ⇒ Object
Returns the value of attribute skills_prefix.
15 16 17 |
# File 'lib/serializer.rb', line 15 def skills_prefix @skills_prefix end |
Instance Method Details
#dump(dir, base_name, items) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/serializer.rb', line 104 def dump(dir,base_name,items) if (items && !items.empty?) count = 1 items.each() do |item| filename = base_name + "_" if (item.respond_to? :name) filename += item.name.gsub(/\//,"_").gsub(/\s/,"_") else filename += count.to_s end filename += ".yaml" File.open("#{dir}/#{filename}",'w') { |out| YAML::dump(item,out) } count += 1 end end end |
#load(dir) ⇒ Object
Loads the resume artifacts from the given directory
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/serializer.rb', line 29 def load(dir) if (!File.exists?(dir)) raise "#{dir} doesn't exist" end resume = Resume.new cores = read_cores(dir,core_prefix) if (cores.size > 1) if (core_to_use) cores.each() { |core| resume.core = core if core.name == core_to_use } else raise "You must specify a core resume to use since there are #{cores.size} of them" end else resume.core = cores[0] end raise "#{core_to_use} didn't match any resumes" if !resume.core config_filename = "#{dir}/config_#{core_to_use}.yaml" config = File.open(config_filename) { |yf| YAML::load( yf ) } if File.exists?(config_filename) resume.skills = File.open( "#{dir}/#{skills_prefix}.yaml" ) { |yf| YAML::load( yf ) } if File.exists?("#{dir}/#{skills_prefix}.yaml") resume.experience = read(dir,experience_prefix) warn "No experience detected" if resume.experience.size == 0 resume.education = read(dir,education_prefix) resume.references = read(dir,references_prefix) resume.samples = read(dir,samples_prefix) resume.experience.sort!.reverse! resume.education.sort!.reverse! resume.samples.sort!.reverse! resume.experience.each() do |xp| xp.positions.each() do |position| if (filter_file) require filter_file if (FILTER.respond_to? :filter_config=) FILTER.filter_config=config end position.achievements = FILTER.filter_achievements(position.achievements) end end xp.positions.sort!.reverse! end return resume end |
#read(dir, base_name, allow_prefix_only = false) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/serializer.rb', line 72 def read(dir,base_name,allow_prefix_only=false) list = Array.new files = Dir.glob("#{dir}/#{base_name}_*.yaml") if (allow_prefix_only) prefix_only_name = "#{dir}/#{base_name}.yaml"; files << prefix_only_name if File.exists? prefix_only_name end files.each do |file| list << File.open( file ) { |yf| YAML::load( yf ) } end list end |
#read_cores(dir, base_name) ⇒ Object
85 86 87 |
# File 'lib/serializer.rb', line 85 def read_cores(dir,base_name) return read(dir,base_name,true) end |
#store(dir, resume) ⇒ Object
Stores the resume artifacts to the given directory.
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/serializer.rb', line 90 def store(dir,resume) if File.exists?(dir) rm(Dir.glob("#{dir}/*.yaml")) else mkdir(dir) end File.open("#{dir}/resume.yaml",'w') { |out| YAML::dump(resume.core,out) } dump(dir,"experience",resume.experience) dump(dir,"education",resume.education) dump(dir,"reference",resume.references) dump(dir,"samples",resume.samples) File.open("#{dir}/skills.yaml",'w') { |out| YAML::dump(resume.skills,out) } end |