Class: JST::Parser

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#debugObject

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

Parameters:

  • value

    the value to set the attribute educations to.



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

Parameters:

  • value

    the value to set the attribute jst_response to.



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

Parameters:

  • value

    the value to set the attribute name to.



6
7
8
# File 'lib/jst.rb', line 6

def name=(value)
  @name = value
end

#positions=(value) ⇒ Object (writeonly)

Sets the attribute positions

Parameters:

  • value

    the value to set the attribute positions to.



6
7
8
# File 'lib/jst.rb', line 6

def positions=(value)
  @positions = value
end

#rank=(value) ⇒ Object (writeonly)

Sets the attribute rank

Parameters:

  • value

    the value to set the attribute rank to.



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

Parameters:

  • value

    the value to set the attribute skills_all to.



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

Parameters:

  • value

    the value to set the attribute skills_graduate to.



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

Parameters:

  • value

    the value to set the attribute skills_lower to.



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

Parameters:

  • value

    the value to set the attribute skills_upper to.



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

Parameters:

  • value

    the value to set the attribute skills_vocational to.



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