Class: SalesforceCertificationCalculator::FileReader
- Inherits:
-
Object
- Object
- SalesforceCertificationCalculator::FileReader
- Defined in:
- lib/salesforce_certification_calculator/file_reader.rb
Constant Summary collapse
Instance Method Summary collapse
-
#extract_initial_exam_data(exam) ⇒ Exam
Gets all details about an exam’s sections, including names and weights.
-
#generate_exams_list ⇒ Array
Gets list of all exams in the database, including their names and file paths.
-
#initialize ⇒ FileReader
constructor
Creates FileReader object by establishing a base path.
Constructor Details
#initialize ⇒ FileReader
Creates FileReader object by establishing a base path
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/salesforce_certification_calculator/file_reader.rb', line 8 def initialize sfc_gems = [] gems_path = ENV["HOME"] + "/gems/gems" all_gems = Dir.children(gems_path) all_gems.each do |gem| if gem.include? "salesforce_certification_calculator" sfc_gems.push(gem) end end sfc_gems.sort latest_sfc = sfc_gems[sfc_gems.length - 1] @base_path = gems_path + "/" + latest_sfc end |
Instance Method Details
#extract_initial_exam_data(exam) ⇒ Exam
Gets all details about an exam’s sections, including names and weights
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/salesforce_certification_calculator/file_reader.rb', line 62 def extract_initial_exam_data(exam) file_path = @base_path + "/" + exam.file doc = File.open(file_path) { |f| Nokogiri::XML(f) } names = doc.xpath("//name") weights = doc.xpath("//weight") (0..names.length-1).each do |i| exam.add_section(names[i].content, weights[i].content.to_i) end return exam end |
#generate_exams_list ⇒ Array
Gets list of all exams in the database, including their names and file paths
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/salesforce_certification_calculator/file_reader.rb', line 34 def generate_exams_list exams = [] files = Dir.glob("data/*xml", base: @base_path) files.each do |file| exam = SFC::Exam.new file_path = @base_path + "/" + file doc = File.open(file_path) { |f| Nokogiri::XML(f) } title = doc.at_xpath("//title") exam.title = title.content exam.file = file exams.push(exam) end return exams end |