Class: Zold::Show

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

Overview

Show command

Instance Method Summary collapse

Constructor Details

#initialize(wallets:, copies:, log: Log::NULL) ⇒ Show

Returns a new instance of Show.



44
45
46
47
48
# File 'lib/zold/commands/show.rb', line 44

def initialize(wallets:, copies:, log: Log::NULL)
  @wallets = wallets
  @copies = copies
  @log = log
end

Instance Method Details

#run(args = []) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/zold/commands/show.rb', line 50

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, copies: @copies, log: @log).run(args)
  else
    total = Amount::ZERO
    mine.map { |i| Id.new(i) }.each do |id|
      @wallets.acq(id) do |w|
        total += show(w, opts)
      end
    end
    total
  end
end