Class: Kanrisuru::Core::Yum::Parser::Repolist

Inherits:
Base
  • Object
show all
Defined in:
lib/kanrisuru/core/yum/parsers/repolist.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
# File 'lib/kanrisuru/core/yum/parsers/repolist.rb', line 8

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

  rows = []
  current_row = nil

  lines.each do |line|
    case line
    when /^Repo-id/
      if current_row
        rows << current_row
        current_row = nil
      end

      current_row = Kanrisuru::Core::Yum::Repolist.new
      current_row.id = extract_single_yum_line(line)
    when /^Repo-name/
      current_row.name = extract_single_yum_line(line)
    when /^Repo-revision/
      current_row.revision = extract_single_yum_line(line).to_i
    when /^Repo-updated/, /^Updated/
      text = extract_single_yum_line(line)
      current_row.updated = DateTime.parse(text)
    when /^Repo-pkgs/
      current_row.packages = extract_single_yum_line(line).to_i
    when /^Repo-size/
      size = Kanrisuru::Util::Bits.normalize_size(extract_single_yum_line(line))
      current_row.repo_size = size
    when /^Repo-mirrors/
      current_row.mirrors = extract_single_yum_line(line)
    when /^Repo-metalink/
      current_row.metalink = extract_single_yum_line(line)
    when /^Repo-baseurl/
      current_row.baseurl = extract_single_yum_line(line).split[0]
    when /^Repo-expire/
      current_row.expire = extract_single_yum_line(line)
    when /^Repo-filename/
      current_row.filename = extract_single_yum_line(line)
    when /^Repo-available-pkgs/
      current_row.available_packages = extract_single_yum_line(line).to_i
    when /^Filter/
      current_row.filters = extract_single_yum_line(line)
    end
  end

  rows << current_row
  rows
end