Class: Kanrisuru::Core::Yum::Parser::Info

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

Class Method Summary collapse

Methods inherited from Base

extract_single_yum_line, parse_yum_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
# File 'lib/kanrisuru/core/yum/parsers/info.rb', line 8

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

  rows = []
  current_row = nil
  description = ''

  lines.each do |line|
    next unless line.include?(': ')

    case line
    when /^Name/
      unless current_row.nil?
        current_row.description = description.strip
        description = ''
        rows << current_row
      end

      current_row = Kanrisuru::Core::Yum::PackageDetail.new
      current_row.package = extract_single_yum_line(line)
    when /^Arch/, /^Architecture/
      current_row.architecture = extract_single_yum_line(line)
    when /^Version/
      current_row.version = extract_single_yum_line(line)
    when /^Release/
      current_row.release = extract_single_yum_line(line)
    when /^Source/
      current_row.source = extract_single_yum_line(line)
    when /^Repository/
      current_row.repository = extract_single_yum_line(line)
    when /^Summary/
      current_row.summary = extract_single_yum_line(line)
    when /^URL/, /^Url/
      current_row.url = extract_single_yum_line(line)
    when /^License/
      current_row.license = extract_single_yum_line(line)
    when /^From repo/
      current_row.yum_id = extract_single_yum_line(line)
    when /^Size/
      size = Kanrisuru::Util::Bits.normalize_size(extract_single_yum_line(line))
      current_row.install_size = size
    when /^Description/
      description = extract_single_yum_line(line)
    else
      next if line == ''

      description += " #{extract_single_yum_line(line).strip}"
    end
  end

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

  rows
end