morpheus-cli 4.2.15 → 4.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -461,7 +461,7 @@ class Morpheus::Cli::PriceSetsCommand
461
461
  private
462
462
 
463
463
  def currency_sym(currency)
464
- Money::Currency.new((currency || 'usd').to_sym).symbol
464
+ Money::Currency.new((currency.to_s != '' ? currency : 'usd').to_sym).symbol
465
465
  end
466
466
 
467
467
  def price_prefix(price)
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Morpheus
3
3
  module Cli
4
- VERSION = "4.2.15"
4
+ VERSION = "4.2.16"
5
5
  end
6
6
  end
@@ -365,14 +365,8 @@ def format_number(n, opts={})
365
365
  return out
366
366
  end
367
367
 
368
- def format_sig_dig(n, sig_dig=3)
369
- out = ""
370
- parts = n.to_f.round(sig_dig).to_s.split(".")
371
- if parts.size > 1 && sig_dig
372
- parts[1] = parts[1].ljust(sig_dig, "0")
373
- end
374
- out << parts.join(".")
375
- return out
368
+ def format_sig_dig(n, sigdig=3)
369
+ sprintf("%.#{sigdig}f", n)
376
370
  end
377
371
 
378
372
  def currency_sym(currency)
@@ -382,22 +376,16 @@ end
382
376
  # returns currency amount formatted like "$4,5123.00". 0.00 is formatted as "$0"
383
377
  # this is not ideal
384
378
  def format_money(amount, currency='usd', opts={})
385
- if amount.to_f == 0
379
+ amount = amount.to_f
380
+ if amount == 0
386
381
  return currency_sym(currency).to_s + "0"
387
382
  # elsif amount.to_f < 0.01
388
383
  # # return exponent notation like 3.4e-09
389
384
  # return currency_sym(currency).to_s + "#{amount}"
390
385
  else
391
- rtn = amount.to_f.round(2).to_s
392
- if rtn.index('.').nil?
393
- rtn += '.00'
394
- elsif rtn.split('.')[1].length < 2
395
- rtn = rtn + (['0'] * (2 - rtn.split('.')[1].length) * '')
396
- end
397
- dollars,cents = rtn.split(".")
398
- rtn = currency_sym(currency).to_s + format_number(dollars.to_i.abs) + "." + cents
399
-
400
- if dollars.to_i < 0
386
+ sigdig = opts[:sigdig] ? opts[:sigdig].to_i : 2
387
+ rtn = currency_sym(currency).to_s + format_number(sprintf("%.#{sigdig}f", amount))
388
+ if amount.to_i < 0
401
389
  rtn = "(#{rtn})"
402
390
  if opts[:minus_color]
403
391
  rtn = "#{opts[:minus_color]}#{rtn}#{opts[:return_color] || cyan}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: morpheus-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.15
4
+ version: 4.2.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Estes
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2020-05-21 00:00:00.000000000 Z
14
+ date: 2020-06-18 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler