Class: GenesisRuby::Utils::Money::Format
- Inherits:
-
Object
- Object
- GenesisRuby::Utils::Money::Format
- Defined in:
- lib/genesis_ruby/utils/money/format.rb
Overview
Money Helper
Instance Attribute Summary collapse
-
#strategy ⇒ Object
Returns the value of attribute strategy.
Instance Method Summary collapse
-
#convert ⇒ Object
Execute Convert Strategy.
-
#initialize(strategy) ⇒ Format
constructor
A new instance of Format.
-
#valid_amount_exponent? ⇒ Boolean
Validate the given amount against the defined currency exponent.
Constructor Details
#initialize(strategy) ⇒ Format
Returns a new instance of Format.
13 14 15 |
# File 'lib/genesis_ruby/utils/money/format.rb', line 13 def initialize(strategy) @strategy = strategy end |
Instance Attribute Details
#strategy ⇒ Object
Returns the value of attribute strategy.
11 12 13 |
# File 'lib/genesis_ruby/utils/money/format.rb', line 11 def strategy @strategy end |
Instance Method Details
#convert ⇒ Object
Execute Convert Strategy
18 19 20 21 22 23 24 |
# File 'lib/genesis_ruby/utils/money/format.rb', line 18 def convert unless valid_amount_exponent? raise GenesisRuby::InvalidArgumentError, 'Currency exponent do not match the given amount' end strategy.convert end |
#valid_amount_exponent? ⇒ Boolean
Validate the given amount against the defined currency exponent
27 28 29 30 31 |
# File 'lib/genesis_ruby/utils/money/format.rb', line 27 def valid_amount_exponent? amount_sign, amount_digits, amount_base, amount_exponent = strategy.amount.split # rubocop:disable Lint/UselessAssignment !amount_sign.negative? && (amount_digits.length - amount_exponent) <= strategy.currency_exponent end |