Class: RepomdParser::RepomdXmlParser
- Inherits:
-
Object
- Object
- RepomdParser::RepomdXmlParser
- Defined in:
- lib/repomd_parser/repomd_xml_parser.rb
Overview
repomd_parser – Ruby gem to parse RPM repository metadata Copyright © 2018 Ivan Kapelyukhin, SUSE Linux GmbH
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Instance Method Summary collapse
Instance Method Details
#parse(io_object) ⇒ Object
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 |
# File 'lib/repomd_parser/repomd_xml_parser.rb', line 25 def parse(io_object) files = [] xml = Nokogiri::XML(io_object) xml.xpath('/xmlns:repomd/xmlns:data').each do |data_node| type = data_node.attr('type').to_sym hash = {} data_node.xpath('./*').each do |node| hash[node.name.to_sym] = { value: node.text.to_s } node.attributes.each do |name, attr| hash[node.name.to_sym][name.to_sym] = attr.value end end files << RepomdParser::Reference.new( location: hash[:location][:href], checksum_type: hash[:checksum][:type], checksum: hash[:checksum][:value], type: type, size: hash[:size] ? hash[:size][:value].to_i : nil ) end files end |
#parse_file(filename) ⇒ Object
19 20 21 22 23 |
# File 'lib/repomd_parser/repomd_xml_parser.rb', line 19 def parse_file(filename) File.open(filename) do |fh| parse(fh) end end |