Class: PmdTester::ProjectsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/pmdtester/parsers/projects_parser.rb

Overview

The ProjectsParser is a class responsible of parsing the projects XML file to get the Project object array

Instance Method Summary collapse

Instance Method Details

#parse(list_file) ⇒ Object

Raises:



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pmdtester/parsers/projects_parser.rb', line 9

def parse(list_file)
  schema = Nokogiri::XML::Schema(File.read(schema_file_path))
  document = Nokogiri::XML(File.read(list_file))

  errors = schema.validate(document)
  raise ProjectsParserException.new(errors), "Schema validate failed: In #{list_file}" unless errors.empty?

  projects = []
  document.xpath('//project').each do |project|
    projects.push(Project.new(project))
  end
  projects
end

#schema_file_pathObject



23
24
25
# File 'lib/pmdtester/parsers/projects_parser.rb', line 23

def schema_file_path
  ResourceLocator.locate('config/projectlist_1_2_0.xsd')
end