Class: Zold::Invoice
- Inherits:
-
Object
- Object
- Zold::Invoice
- Defined in:
- lib/zold/commands/invoice.rb
Overview
Generate invoice
Instance Method Summary collapse
-
#initialize(wallets:, log: Log::Quiet.new) ⇒ Invoice
constructor
A new instance of Invoice.
- #invoice(wallet, opts) ⇒ Object
- #run(args = []) ⇒ Object
Constructor Details
Instance Method Details
#invoice(wallet, opts) ⇒ Object
56 57 58 59 60 |
# File 'lib/zold/commands/invoice.rb', line 56 def invoice(wallet, opts) invoice = "#{Prefixes.new(wallet).create(opts[:length])}@#{wallet.id}" @log.info(invoice) invoice end |
#run(args = []) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/zold/commands/invoice.rb', line 38 def run(args = []) opts = Slop.parse(args, help: true, suppress_errors: true) do |o| o. = "Usage: zold invoice ID [options] Where: 'ID' is the wallet ID of the money receiver Available options:" o.integer '--length', 'The length of the invoice prefix (default: 8)', default: 8 o.bool '--help', 'Print instructions' end mine = Args.new(opts, @log).take || return raise 'Receiver wallet ID is required' if mine[0].nil? wallet = @wallets.find(Zold::Id.new(mine[0])) raise 'Wallet doesn\'t exist, do \'fetch\' first' unless wallet.exists? invoice(wallet, opts) end |