Module: Aranha::Parsers::Ofx::Data::MonetarySupport
- Included in:
- BankAccount, CreditAccount, InvestmentAccount, Transaction
- Defined in:
- lib/aranha/parsers/ofx/data/monetary_support.rb
Instance Method Summary collapse
-
#method_missing(meth, *args) ⇒ Object
:nodoc: # rubocop:disable Style/MissingRespondToMissing.
-
#monetary_method_call?(meth) ⇒ Boolean
:nodoc:.
-
#original_method(meth) ⇒ Object
:nodoc:.
-
#pennies_for(amount) ⇒ Object
Returns pennies for a given string amount, i.e: ‘-123.45’ => -12345 ‘123’ => 12300.
-
#respond_to?(meth) ⇒ Boolean
:nodoc:.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
:nodoc: # rubocop:disable Style/MissingRespondToMissing
30 31 32 33 34 35 36 |
# File 'lib/aranha/parsers/ofx/data/monetary_support.rb', line 30 def method_missing(meth, *args) # :nodoc: # rubocop:disable Style/MissingRespondToMissing if monetary_method_call?(meth) pennies_for(send(original_method(meth))) else super end end |
Instance Method Details
#monetary_method_call?(meth) ⇒ Boolean
:nodoc:
25 26 27 28 |
# File 'lib/aranha/parsers/ofx/data/monetary_support.rb', line 25 def monetary_method_call?(meth) # :nodoc: orig = original_method(meth) self.class.monies.include?(orig) && meth.to_s == "#{orig}_in_pennies" end |
#original_method(meth) ⇒ Object
:nodoc:
19 20 21 22 23 |
# File 'lib/aranha/parsers/ofx/data/monetary_support.rb', line 19 def original_method(meth) # :nodoc: meth.to_s.sub('_in_pennies', '').to_sym rescue StandardError nil end |
#pennies_for(amount) ⇒ Object
Returns pennies for a given string amount, i.e:
'-123.45' => -12345
'123' => 12300
11 12 13 14 15 16 17 |
# File 'lib/aranha/parsers/ofx/data/monetary_support.rb', line 11 def pennies_for(amount) return nil if amount == '' int, fraction = amount.scan(/\d+/) i = fraction.to_s.strip =~ /[1-9]/ ? "#{int}#{fraction[0, 2]}".to_i : int.to_i * 100 amount =~ /^\s*-\s*\d+/ ? -i : i end |
#respond_to?(meth) ⇒ Boolean
:nodoc:
38 39 40 |
# File 'lib/aranha/parsers/ofx/data/monetary_support.rb', line 38 def respond_to?(meth) # :nodoc: monetary_method_call?(meth) || super end |