lib/punky_brewster/cli.rb in punky_brewster-1.2.0 vs lib/punky_brewster/cli.rb in punky_brewster-1.3.0

- old
+ new

@@ -9,16 +9,27 @@ def version say "Punky Brewster version #{VERSION}" end desc "list", "Show current beer list" - method_option :sort, default: "name", enum: %w( name price abv ) + method_option :sort, default: "name", enum: %w( name price abv abv_per_dollar ) + method_option :cheapskate, type: :boolean, default: false + method_option :holla_for_dollar, type: :boolean, default: false def list + show_abv_per_dollar = options[:holla_for_dollar] || options[:cheapskate] + beers = BeerListRequest.new.beers - sorted = beers.sort_by { |beer| beer.send(options[:sort]) } + 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| - [beer.name, "$%0.2f/L" % beer.price, "%0.1f%" % beer.abv] + 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