Module: Octonaut::Printer

Includes:
Octonaut::Printers::Authorizations, Octonaut::Printers::Repositories, Octonaut::Printers::Users
Included in:
Octonaut
Defined in:
lib/octonaut/printer.rb

Constant Summary

Constants included from Octonaut::Printers::Users

Octonaut::Printers::Users::USER_FIELDS

Constants included from Octonaut::Printers::Repositories

Octonaut::Printers::Repositories::REPOSITORY_FIELDS

Instance Method Summary collapse

Methods included from Octonaut::Printers::Users

#ls_users, #print_csv_users, #print_user_table, #print_users

Methods included from Octonaut::Printers::Repositories

#ls_repos, #print_csv_repos, #print_repo_table, #print_repos

Methods included from Octonaut::Printers::Authorizations

#ls_authorizations

Instance Method Details

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/octonaut/printer.rb', line 16

def print_csv(array, options = {})
  raise ArgumentError.new("array of hashes required") unless array.first.kind_of?(Hash)
  fields  = options[:fields]
  headers = fields.values
  keys    = fields.keys

  puts headers.to_csv

  array.each do |item|
    data = []
    keys.each {|key| data << item[key] }
    puts item.inspect
    puts data
  end
end


12
13
14
# File 'lib/octonaut/printer.rb', line 12

def print_table(data)
  data.each { | key, value | puts "#{key.rjust(data.keys.map(&:length).max)} #{value}" }
end