Class: RepomdParser::PrimaryXmlParser

Inherits:
BaseParser
  • Object
show all
Defined in:
lib/repomd_parser/primary_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

Methods inherited from BaseParser

#parse, #parse_file

Instance Method Details

#characters(string) ⇒ Object



39
40
41
42
43
44
# File 'lib/repomd_parser/primary_xml_parser.rb', line 39

def characters(string)
  return unless %i[name arch checksum summary description rpm:license].include? @current_node

  @package[@current_node] ||= ''
  @package[@current_node] += string.strip
end

#end_element(name) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/repomd_parser/primary_xml_parser.rb', line 46

def end_element(name)
  return unless name == 'package'

  @referenced_files << RepomdParser::Reference.new(
    location: @package[:location],
    checksum_type: @package[:checksum_type],
    checksum: @package[:checksum],
    type: :rpm,
    size: @package[:size].to_i,
    arch: @package[:arch],
    version: @package[:version],
    release: @package[:release],
    name: @package[:name],
    summary: @package[:summary],
    description: @package[:description],
    license: @package[:'rpm:license'],
    build_time: Time.at(@package[:build_time].to_i).utc,
    epoch: @package[:epoch]
  )
end

#start_element(name, attrs = []) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/repomd_parser/primary_xml_parser.rb', line 19

def start_element(name, attrs = [])
  @current_node = name.to_sym
  case name
  when 'package'
    @package = {}
  when 'version'
    @package[:version] = get_attribute(attrs, 'ver')
    @package[:release] = get_attribute(attrs, 'rel')
    @package[:epoch] = get_attribute(attrs, 'epoch')
  when 'location'
    @package[:location] = get_attribute(attrs, 'href')
  when 'checksum'
    @package[:checksum_type] = get_attribute(attrs, 'type')
  when 'size'
    @package[:size] = get_attribute(attrs, 'package').to_i
  when 'time'
    @package[:build_time] = get_attribute(attrs, 'build')
  end
end