Class: Zold::Show

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/commands/show.rb

Overview

Show command

Instance Method Summary collapse

Constructor Details

#initialize(wallets:, log: Log::Quiet.new) ⇒ Show

Returns a new instance of Show.



36
37
38
39
# File 'lib/zold/commands/show.rb', line 36

def initialize(wallets:, log: Log::Quiet.new)
  @wallets = wallets
  @log = log
end

Instance Method Details

#run(args = []) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/zold/commands/show.rb', line 41

def run(args = [])
  opts = Slop.parse(args, help: true, suppress_errors: true) do |o|
    o.banner = "Usage: zold show [ID...] [options]
Available options:"
    o.bool '--help', 'Print instructions'
  end
  mine = Args.new(opts, @log).take || return
  if mine.empty?
    require_relative 'list'
    List.new(wallets: @wallets, log: @log).run(args)
  else
    total = Amount::ZERO
    mine.each do |id|
      total += show(@wallets.find(Id.new(id)), opts)
    end
    total
  end
end