Class: JsonResume::Formatter
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(hash) ⇒ Formatter
Returns a new instance of Formatter.
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/json_resume/formatter.rb', line 13
def initialize(hash)
@hash = hash
@hash_proc = proc do |k, v|
v = k if v.nil? v.delete_if(&@hash_proc) if [Hash, Array].any? { |x| v.instance_of? x }
v.empty?
end
end
|
Instance Attribute Details
Returns the value of attribute hash.
11
12
13
|
# File 'lib/json_resume/formatter.rb', line 11
def hash
@hash
end
|
Instance Method Details
#add_last_marker_on_field(field_name) ⇒ Object
55
56
57
58
59
60
61
62
|
# 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 ⇒ Object
38
39
40
41
42
43
44
|
# 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 ⇒ Object
30
31
32
33
34
35
36
|
# 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
|
46
47
48
49
50
51
52
53
|
# 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 ⇒ Object
24
25
26
27
28
|
# 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) ⇒ Object
92
93
94
95
96
97
98
99
|
# 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
|
64
65
66
67
|
# File 'lib/json_resume/formatter.rb', line 64
def cleanse
@hash.delete_if(&@hash_proc)
self
end
|
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# 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
%w(grad_courses undergrad_courses).each do |course|
add_padding(course)
end
self
end
|
79
80
81
|
# File 'lib/json_resume/formatter.rb', line 79
def format_string(_)
fail(NotImplementedError.new('format_string not impl in formatter'), '')
end
|
69
70
71
72
73
74
75
76
77
|
# 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) ⇒ Boolean
83
84
85
|
# File 'lib/json_resume/formatter.rb', line 83
def item_false?(item)
item == false || item == 'false'
end
|
#purge_gpa ⇒ Object
87
88
89
90
|
# 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
|