Class: Wooget::PackageListFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/wooget/util/package_list_formatter.rb

Class Method Summary collapse

Class Method Details

.format_list(package_hash, format, show_binary = false) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/wooget/util/package_list_formatter.rb', line 3

def self.format_list package_hash, format, show_binary=false

  package_hash.values.each {|list| Package.process_binary_packages(list)}

  case format
    when "shell", :shell
      output = ""
      package_hash.each do |repo, packages|
        output << "### #{repo.upcase}\n"
        packages.each do |package|
          next if package.is_binary and not show_binary

          output << "  #{package.package_id} #{"(B)" if package.has_binary and not show_binary} - #{package.version} \n"
        end
        output << "\n"
      end
      output << "- (B) : binary variant available"
      output
    when "json", :json

      unless show_binary
        package_hash.each do |_,packages|
          packages.delete_if {|p| p.is_binary}
        end
      end
      package_hash.to_json
  end
end

.format_package(package_hash, format, package_id = false) ⇒ Object



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
# File 'lib/wooget/util/package_list_formatter.rb', line 32

def self.format_package package_hash, format, package_id=false
  package_hash.values.each {|list| Package.process_binary_packages(list)}

  package = nil
  package_hash.each do |_, packages|
    package = packages.find {|p| p.package_id == package_id}
    break if package
  end

  return "Package '#{package_id}' not found in repos - #{package_hash.keys.join(",")}" unless package

  case format
    when "shell", :shell
      output = ""
      output << "### #{package.package_id}\n"
      %i(version authors created last_updated summary description project_url release_notes
          is_latest_version url has_binary dependencies download_count tags).each do |prop|
        output << "## #{prop.capitalize}\n"
        output << "  " +package.send(prop).to_s + "\n"

      end
      output
    when "json", :json
      package.to_json
  end
end