Class: Kanrisuru::Core::Apt::Parser::Show
- Defined in:
- lib/kanrisuru/core/apt/parsers/show.rb
Class Method Summary collapse
Methods inherited from Base
extract_single_line, parse_apt_line, parse_apt_sources, parse_comma_values
Class Method Details
.parse(command) ⇒ Object
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 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/kanrisuru/core/apt/parsers/show.rb', line 9 def parse(command) lines = command.to_a rows = [] current_row = nil description = '' lines.each do |line| next if line == 'WARNING: apt does not have a stable CLI interface. Use with caution in scripts.' next if ['', nil, '.'].include?(line) case line when /^Package:/ unless current_row.nil? current_row.description = description.strip description = '' rows << current_row end current_row = Kanrisuru::Core::Apt::PackageDetail.new current_row.package = extract_single_line(line) when /^Version:/ current_row.version = extract_single_line(line) when /^Priority:/ current_row.priority = extract_single_line(line) when /^Section:/ current_row.section = extract_single_line(line) when /^Origin:/ current_row.origin = extract_single_line(line) when /^Maintainer:/ current_row.maintainer = extract_single_line(line) when /^Original-Maintainer:/ current_row.original_maintainer = extract_single_line(line) when /^Bugs:/ current_row.bugs = extract_single_line(line) when /^Installed-Size:/ size = Kanrisuru::Util::Bits.normalize_size(extract_single_line(line)) current_row.install_size = size when /^Download-Size:/ size = Kanrisuru::Util::Bits.normalize_size(extract_single_line(line)) current_row.download_size = size when /^Depends:/ current_row.dependencies = parse_comma_values(extract_single_line(line)) when /^Provides:/ current_row.provides = parse_comma_values(extract_single_line(line)) when /^Recommends:/ current_row.recommends = parse_comma_values(extract_single_line(line)) when /^Suggests:/ current_row.suggests = parse_comma_values(extract_single_line(line)) when /^Breaks:/ current_row.breaks = parse_comma_values(extract_single_line(line)) when /^Conflicts:/ current_row.conflicts = parse_comma_values(extract_single_line(line)) when /^Replaces:/ current_row.replaces = parse_comma_values(extract_single_line(line)) when /^Homepage:/ current_row.homepage = extract_single_line(line) when /^Task:/ current_row.task = parse_comma_values(extract_single_line(line)) when /^Supported:/ current_row.supported = extract_single_line(line) when /^APT-Sources:/ current_row.apt_sources = parse_apt_sources(extract_single_line(line)) when /^APT-Manual-Installed:/ current_row.apt_manual_installed = extract_single_line(line) == 'yes' when /^Description:/ current_row.summary = extract_single_line(line) else description += " #{line.strip}" end end current_row.description = description.strip rows << current_row rows end |