Class: JST::Parser
- Inherits:
-
Object
- Object
- JST::Parser
- Defined in:
- lib/jst.rb
Defined Under Namespace
Classes: BadPDFError, UnknownPDFParsingError
Constant Summary collapse
- BRANCH_ARMY =
'United States Army'
- BRANCH_NAVY =
'United States Navy'
- BRANCH_AIR =
'United States Air Force'
- BRANCH_MARINES =
'United States Marine Corps'
- BRANCH_COAST =
'United States Coast Guard'
- BRANCH_DOD =
'Department of Defense'
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#educations ⇒ Object
writeonly
Sets the attribute educations.
-
#jst_response ⇒ Object
writeonly
Sets the attribute jst_response.
-
#name ⇒ Object
writeonly
Sets the attribute name.
-
#positions ⇒ Object
writeonly
Sets the attribute positions.
-
#rank ⇒ Object
writeonly
Sets the attribute rank.
-
#skills_all ⇒ Object
writeonly
Sets the attribute skills_all.
-
#skills_graduate ⇒ Object
writeonly
Sets the attribute skills_graduate.
-
#skills_lower ⇒ Object
writeonly
Sets the attribute skills_lower.
-
#skills_upper ⇒ Object
writeonly
Sets the attribute skills_upper.
-
#skills_vocational ⇒ Object
writeonly
Sets the attribute skills_vocational.
Instance Method Summary collapse
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
5 6 7 |
# File 'lib/jst.rb', line 5 def debug @debug end |
#educations=(value) ⇒ Object (writeonly)
Sets the attribute educations
6 7 8 |
# File 'lib/jst.rb', line 6 def educations=(value) @educations = value end |
#jst_response=(value) ⇒ Object (writeonly)
Sets the attribute jst_response
6 7 8 |
# File 'lib/jst.rb', line 6 def jst_response=(value) @jst_response = value end |
#name=(value) ⇒ Object (writeonly)
Sets the attribute name
6 7 8 |
# File 'lib/jst.rb', line 6 def name=(value) @name = value end |
#positions=(value) ⇒ Object (writeonly)
Sets the attribute positions
6 7 8 |
# File 'lib/jst.rb', line 6 def positions=(value) @positions = value end |
#rank=(value) ⇒ Object (writeonly)
Sets the attribute rank
6 7 8 |
# File 'lib/jst.rb', line 6 def rank=(value) @rank = value end |
#skills_all=(value) ⇒ Object (writeonly)
Sets the attribute skills_all
6 7 8 |
# File 'lib/jst.rb', line 6 def skills_all=(value) @skills_all = value end |
#skills_graduate=(value) ⇒ Object (writeonly)
Sets the attribute skills_graduate
6 7 8 |
# File 'lib/jst.rb', line 6 def skills_graduate=(value) @skills_graduate = value end |
#skills_lower=(value) ⇒ Object (writeonly)
Sets the attribute skills_lower
6 7 8 |
# File 'lib/jst.rb', line 6 def skills_lower=(value) @skills_lower = value end |
#skills_upper=(value) ⇒ Object (writeonly)
Sets the attribute skills_upper
6 7 8 |
# File 'lib/jst.rb', line 6 def skills_upper=(value) @skills_upper = value end |
#skills_vocational=(value) ⇒ Object (writeonly)
Sets the attribute skills_vocational
6 7 8 |
# File 'lib/jst.rb', line 6 def skills_vocational=(value) @skills_vocational = value end |
Instance Method Details
#parse(pdf_file) ⇒ Object
19 20 21 22 23 24 25 26 27 28 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 |
# File 'lib/jst.rb', line 19 def parse(pdf_file) unless @debug @debug = false end unless pdf_file.nil? || pdf_file.size <= 0 begin pdf_reader = PDF::Reader.new(pdf_file) # Iterate through each page & concat pdf_text = '' pdf_reader.pages.each do |page| pdf_text += page.text end # Pull out various attributes @name ||= pdf_text.match(/Name:(.+)$/) @name = @name[@name.length - 1].gsub!(/^\s+/,'') unless @name.nil? @rank ||= pdf_text.match(/Rank:(.+)$/) @rank = @rank[@rank.length - 1].gsub!(/^\s+/,'') unless @rank.nil? @status ||= pdf_text.match(/Status:(.+)$/) @status = @status[@status.length - 1].gsub!(/^\s+/,'') unless @status.nil? parse_experience(pdf_text) create_response() return @jst_response rescue PDF::Reader::MalformedPDFError raise BadPDFError, "Could not parse JST." rescue ArgumentError raise BadPDFError, "PDF text parsing exception." rescue => exc raise UnknownPDFParsingError, "#{exc}" # rescue PDF::Reader::UnknownGlyphWidthError # # Waiting for this exception to be commited from the following pull request: # # https://github.com/yob/pdf-reader/pull/105 # raise UnknownPDFParsingError, "PDF text parsing exception." end end end |