Class: Kanrisuru::Core::Zypper::Parser::Info

Inherits:
Base
  • Object
show all
Defined in:
lib/kanrisuru/core/zypper/parsers/info.rb

Class Method Summary collapse

Methods inherited from Base

extract_single_zypper_line

Class Method Details

.parse(command) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/kanrisuru/core/zypper/parsers/info.rb', line 8

def self.parse(command)
  lines = command.to_a

  rows = []
  current_row = nil
  description = ''
  skip_description = false

  lines.each do |line|
    case line
    when /^Repository/
      repository = extract_single_zypper_line(line)
      next if repository == ''

      unless current_row.nil?
        skip_description = false
        current_row.description = description.strip
        description = ''
        rows << current_row
      end

      current_row = Kanrisuru::Core::Zypper::PackageDetail.new
      current_row.repository = repository
    when /^Name/
      current_row.package = extract_single_zypper_line(line)
    when /^Version/
      current_row.version = extract_single_zypper_line(line)
    when /^Arch/
      current_row.architecture = extract_single_zypper_line(line)
    when /^Vendor/
      current_row.vendor = extract_single_zypper_line(line)
    when /^Support Level/
      current_row.support_level = extract_single_zypper_line(line)
    when /^Installed Size/
      size = Kanrisuru::Util::Bits.normalize_size(extract_single_zypper_line(line))
      current_row.install_size = size
    when /^Installed/
      value = extract_single_zypper_line(line)
      current_row.installed = value == 'Yes'
    when /^Status/
      current_row.status = extract_single_zypper_line(line)
    when /^Source package/
      current_row.source_package = extract_single_zypper_line(line)
    when /^Summary/
      current_row.summary = extract_single_zypper_line(line)
    when /^Description/
      description = extract_single_zypper_line(line)
    when /^Builds binary package/, /^Contents/
      skip_description = true
    else
      next if line == ''
      next if line.include?('Information for package')
      next if line.include?('---------------------------')

      description += " #{line.strip}" unless skip_description
    end
  end

  if current_row
    current_row.description = description.strip
    rows << current_row
  end

  rows
end