virgild-resumetools 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -0,0 +1,6 @@
1
+ 2009-09-17 (Version 0.2.4)
2
+ * Added property helpers to ResumeTools::Resume
3
+ * Added plain text renderer (ResumeTools::Resume#render_plain_text)
4
+
5
+ 2009-09-01
6
+ * Path cleanup
File without changes
File without changes
File without changes
File without changes
@@ -23,12 +23,13 @@
23
23
  # OTHER DEALINGS IN THE SOFTWARE.
24
24
  #++
25
25
 
26
- $:.unshift(File.dirname(__FILE__))
27
-
28
26
  require "extlib"
29
27
  require "uuidtools"
30
28
 
29
+ $:.unshift File.dirname(__FILE__)
30
+
31
31
  require "resumetools/version"
32
32
  require "resumetools/resume/resume"
33
33
  require "resumetools/resume/text_reader"
34
- require "resumetools/resume/pdf"
34
+ require "resumetools/resume/pdf"
35
+ require "resumetools/resume/plain_text"
@@ -0,0 +1,128 @@
1
+ require 'text/format'
2
+
3
+ module ResumeTools
4
+ module Renderer
5
+ class PlainText
6
+ def initialize(resume)
7
+ @resume = resume
8
+ end
9
+
10
+ def render(opts={})
11
+ @item_bullet = "-"
12
+ @header_filler = "-"
13
+ @newline = "\n"
14
+ @format = Text::Format.new
15
+ @format.first_indent = 0
16
+ @format.columns = 80
17
+ @indent = 2
18
+ @lined_headers = true
19
+
20
+ center @resume.full_name
21
+ center @resume.address1
22
+ center @resume.address2
23
+ center @resume.telephone
24
+ center @resume.email
25
+ center @resume.url
26
+ blank_line
27
+
28
+ @resume.sections.each_with_index do |section, n|
29
+ render_section(section)
30
+ blank_line if (n < @resume.sections.length - 1)
31
+ end
32
+ content
33
+ end
34
+
35
+ private
36
+
37
+ def render_section(section)
38
+ header section.title
39
+ render_paragraph(section.para) if section.has_paragraph?
40
+
41
+ section.items.each_with_index do |item, n|
42
+ push_margin do
43
+ render_item(item)
44
+ end
45
+ blank_line if (n < section.items.length - 1)
46
+ end
47
+
48
+ section.periods.each_with_index do |period, n|
49
+ push_margin do
50
+ render_period period
51
+ end
52
+ blank_line if (n < section.periods.length - 1)
53
+ end
54
+ end
55
+
56
+ def render_period(period)
57
+ add_line(period.title) if period.title
58
+ add_line period.line
59
+
60
+ if period.has_items?
61
+ blank_line
62
+ push_margin do
63
+ period.items.each_with_index do |item, n|
64
+ render_item item
65
+ blank_line if (n < period.items.length - 1)
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ def render_item(item)
72
+ add_line "#{@item_bullet} " + item.text
73
+ end
74
+
75
+ def render_paragraph(para)
76
+ push_margin { add_line para }
77
+ end
78
+
79
+ def reset_content
80
+ @text_content = String.new
81
+ end
82
+
83
+ def content
84
+ @text_content ||= String.new
85
+ end
86
+
87
+ def center(line)
88
+ line = @newline if line.nil?
89
+ content << @format.center(line)
90
+ end
91
+
92
+ def add_line(line="")
93
+ line = @newline if line.nil?
94
+ content << @format.format(line)
95
+ end
96
+
97
+ def blank_line
98
+ content << @newline
99
+ end
100
+
101
+ def push_margin(cols=0, &block)
102
+ cols = @indent if (cols == 0)
103
+ previous_margin = @format.left_margin
104
+ @format.left_margin = @format.left_margin + cols
105
+ block.call
106
+ @format.left_margin = previous_margin
107
+ end
108
+
109
+ def header(text)
110
+ add_line(text)
111
+ add_line(@header_filler * text.length) if @lined_headers
112
+ end
113
+ end #class PlainText
114
+
115
+ module PlainTextMethods
116
+ # Render to plain text
117
+ def render_plain_text(opts={})
118
+ renderer = PlainText.new(self)
119
+ renderer.render(opts)
120
+ end
121
+ end #module Methods
122
+
123
+ end #module Renderer
124
+
125
+ Resume.class_eval do
126
+ include Renderer::PlainTextMethods
127
+ end
128
+ end #module ResumeTools
@@ -28,13 +28,7 @@ module ResumeTools
28
28
  # = Resume
29
29
  # Represents a single resume document
30
30
  class Resume
31
-
32
- # The title of the resume
33
- attr_accessor :title
34
-
35
- # The name (or label) for this resume
36
- attr_accessor :name
37
-
31
+
38
32
  # The full name of the subject of this resume
39
33
  attr_accessor :full_name
40
34
 
@@ -57,16 +51,14 @@ module ResumeTools
57
51
  attr_reader :sections
58
52
 
59
53
  # Creates a +Resume+ and passes it to the given block. Returns the created +Resume+.
60
- def self.build(&block)
61
- resume = self.new
62
- yield resume
54
+ def self.build(opts={}, &block)
55
+ resume = self.new(opts)
56
+ block.call(resume)
63
57
  resume
64
58
  end
65
59
 
66
60
  # Creates a new +Resume+ with the given properties
67
61
  def initialize(props={})
68
- @title = props[:title] || ""
69
- @name = props[:name] || "Unnamed Resume"
70
62
  @full_name = props[:full_name] || ""
71
63
  @url = props[:url] || ""
72
64
  @email = props[:email] || ""
@@ -115,7 +107,12 @@ module ResumeTools
115
107
  !self.address2.blank?
116
108
  end
117
109
 
118
- end
110
+ #
111
+ def has_sections?
112
+ !self.sections.empty?
113
+ end
114
+
115
+ end #class Resume
119
116
 
120
117
 
121
118
  # = Section
@@ -140,6 +137,31 @@ module ResumeTools
140
137
  @items = Array.new
141
138
  @periods = Array.new
142
139
  end
140
+
141
+ #
142
+ def has_paragraph?
143
+ !self.para.blank?
144
+ end
145
+
146
+ def has_para?
147
+ self.has_paragraph?
148
+ end
149
+
150
+ #
151
+ def has_items?
152
+ !self.items.empty?
153
+ end
154
+
155
+ #
156
+ def has_periods?
157
+ !self.periods.empty?
158
+ end
159
+
160
+ #
161
+ def has_title?
162
+ !self.title.blank?
163
+
164
+ end
143
165
 
144
166
  # Creates a period and adds it to the list
145
167
  def create_period(props={}, &block)
@@ -200,6 +222,31 @@ module ResumeTools
200
222
  @items = Array.new
201
223
  end
202
224
 
225
+ #
226
+ def has_title?
227
+ !self.title.blank?
228
+ end
229
+
230
+ def has_location?
231
+ !self.location.blank?
232
+ end
233
+
234
+ def has_organization?
235
+ !self.organization.blank?
236
+ end
237
+
238
+ def has_dtstart?
239
+ !self.dtstart.blank?
240
+ end
241
+
242
+ def has_dtend?
243
+ !self.dtend.blank?
244
+ end
245
+
246
+ def has_items?
247
+ !self.items.empty?
248
+ end
249
+
203
250
  # Adds an item
204
251
  def add_item(item)
205
252
  self.items << item
@@ -212,6 +259,22 @@ module ResumeTools
212
259
  self.add_item(item)
213
260
  item
214
261
  end
262
+
263
+ # The period details in a single line
264
+ def line
265
+ elements = Array.new
266
+ elements << self.organization if self.has_organization?
267
+ elements << self.location if self.has_location?
268
+ if self.has_dtstart? && self.has_dtend?
269
+ date = " (#{self.dtstart}) - #{self.dtend})"
270
+ elsif self.has_dtstart? || self.has_dtend?
271
+ value = self.has_dtstart? ? self.dtstart : self.dtend
272
+ date = " (#{value})"
273
+ else
274
+ date = ''
275
+ end
276
+ elements.join(", ").concat("#{date}")
277
+ end
215
278
  end
216
279
 
217
280
 
@@ -28,7 +28,7 @@ unless defined? ResumeTools::VERSION
28
28
  module VERSION
29
29
  MAJOR = 0
30
30
  MINOR = 2
31
- TINY = 3
31
+ TINY = 4
32
32
  STRING = [MAJOR, MINOR, TINY].join('.')
33
33
  end
34
34
  end
@@ -27,8 +27,7 @@ require File.join(File.dirname(__FILE__), "spec_helper")
27
27
 
28
28
 
29
29
  def resume_attributes
30
- { :name => "Physicist Resume",
31
- :title => "Physicist - 30+ yrs experience",
30
+ {
32
31
  :full_name => "Albert Einstein",
33
32
  :url => "http://phys6.science.org/einstein",
34
33
  :email => "albert.einstein@science.org",
@@ -65,15 +64,13 @@ describe "Resume" do
65
64
 
66
65
  it "has initial properties after creation" do
67
66
  @resume = ResumeTools::Resume.new
68
- @resume.name.should == "Unnamed Resume"
69
- @resume.title.should be_blank
70
67
  @resume.full_name.should be_blank
71
68
  @resume.has_url?.should be_false
72
69
  @resume.has_email?.should be_false
73
70
  @resume.has_telephone?.should be_false
74
71
  @resume.has_address1?.should be_false
75
72
  @resume.has_address2?.should be_false
76
- @resume.should have(0).sections
73
+ @resume.has_sections?.should be_false
77
74
  end
78
75
 
79
76
  it "is created with hash properties" do
@@ -84,8 +81,6 @@ describe "Resume" do
84
81
  @resume.has_address1?.should be_true
85
82
  @resume.has_address2?.should be_true
86
83
 
87
- @resume.name.should == @attributes[:name]
88
- @resume.title.should == @attributes[:title]
89
84
  @resume.full_name.should == @attributes[:full_name]
90
85
  @resume.url.should == @attributes[:url]
91
86
  @resume.telephone.should == @attributes[:telephone]
@@ -110,6 +105,7 @@ describe "Section" do
110
105
  end
111
106
 
112
107
  @resume.should have(1).sections
108
+ @resume.has_sections?.should be_true
113
109
  section = @resume.sections[0]
114
110
  section.title.should == @attributes[:title]
115
111
  section.para.should == @attributes[:para]
@@ -118,8 +114,15 @@ describe "Section" do
118
114
  it "should have no items" do
119
115
  section = ResumeTools::Section.new
120
116
  section.should have(0).items
117
+ section.has_items?.should be_false
121
118
  end
122
119
 
120
+ it "should have no periods" do
121
+ section = ResumeTools::Section.new
122
+ section.has_periods?.should be_false
123
+ end
124
+
125
+
123
126
  it "should be able to add items" do
124
127
  section = ResumeTools::Section.new
125
128
  section.create_item do |item|
@@ -130,6 +133,7 @@ describe "Section" do
130
133
  section.should have(2).items
131
134
  section.items[0].text.should == "This is item A."
132
135
  section.items[1].text.should == "This is item B."
136
+ section.has_items?.should be_true
133
137
  end
134
138
 
135
139
  it "is created in the right order" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: virgild-resumetools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Virgil Dimaguila
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-01 00:00:00 -07:00
12
+ date: 2009-09-17 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -73,11 +73,17 @@ extra_rdoc_files: []
73
73
  files:
74
74
  - examples/sample.pdf
75
75
  - examples/sample.resume
76
+ - lib/fonts
77
+ - lib/fonts/Vera.ttf
78
+ - lib/fonts/VeraBd.ttf
79
+ - lib/fonts/VeraBI.ttf
80
+ - lib/fonts/VeraIt.ttf
76
81
  - lib/resumetools
77
82
  - lib/resumetools/grammars
78
83
  - lib/resumetools/grammars/resume.treetop
79
84
  - lib/resumetools/resume
80
85
  - lib/resumetools/resume/pdf.rb
86
+ - lib/resumetools/resume/plain_text.rb
81
87
  - lib/resumetools/resume/resume.rb
82
88
  - lib/resumetools/resume/text_reader.rb
83
89
  - lib/resumetools/version.rb
@@ -93,10 +99,6 @@ files:
93
99
  - tasks/package.rake
94
100
  - tasks/rdoc.rake
95
101
  - tasks/rspec.rake
96
- - fonts/Vera.ttf
97
- - fonts/VeraBd.ttf
98
- - fonts/VeraBI.ttf
99
- - fonts/VeraIt.ttf
100
102
  - CHANGES
101
103
  - LICENSE
102
104
  - Rakefile