-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0ff0de
commit 2cb0d5a
Showing
3 changed files
with
45 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'pdf-reader' | ||
|
||
module AcademicHistory | ||
module PdfProcessor | ||
AcademicEntry = Struct.new(:name, :credits, :number_of_failures, :date_of_completion, :grade) do | ||
def approved? | ||
grade != '***' | ||
end | ||
end | ||
extend self | ||
|
||
def process(file) | ||
reader = PDF::Reader.new(file.path) | ||
academic_entries = [] | ||
|
||
reader.pages.each do |page| | ||
page.text.split("\n").each do |line| | ||
line.match(subject_regex) do |match| | ||
academic_entries << AcademicEntry.new(match[1], match[2], match[3], match[4], match[5]) | ||
end | ||
end | ||
end | ||
|
||
academic_entries | ||
end | ||
|
||
# SubjectName Credits NumberOfFailures DateOfCompletion Concept | ||
def subject_regex | ||
/\s*(.*?)\s+(\d+)\s+(\d+)\s+(#{date_regex.source})\s+(#{concept_regex.source})/ | ||
end | ||
|
||
# The date can be either a date in the format DD/MM/YYYY or ********** | ||
def date_regex | ||
/\*{10}|\d\d\/\d\d\/\d\d\d\d/ | ||
end | ||
|
||
# The concept can be either a number from 0 to 12, S/N or *** | ||
def concept_regex | ||
/Aceptable|Bueno|Muy Bueno|Excelente|S\/C|\*{3}/ | ||
end | ||
end | ||
end |