Class: PunkyBrewster::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/punky_brewster/cli.rb

Instance Method Summary collapse

Instance Method Details

#listObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/punky_brewster/cli.rb', line 17

def list
  show_abv_per_dollar = options[:holla_for_dollar] || options[:cheapskate]

  beers = BeerRepository.list

  if options[:holla_for_dollar]
    sorted = beers.sort { |a, b| b.abv_per_dollar <=> a.abv_per_dollar }
  else
    sorted = beers.sort_by { |beer| beer.send(options[:sort]) }
  end

  rows = sorted.map do |beer|
    row = [beer.name, "$%0.2f/L" % beer.price, "%0.1f%%" % beer.abv]
    row << ("%0.2f%%/$" % beer.abv_per_dollar) if show_abv_per_dollar
    row
  end

  print_table rows
end

#versionObject



9
10
11
# File 'lib/punky_brewster/cli.rb', line 9

def version
  say "Punky Brewster version #{VERSION}"
end