Class: Fintoc::Account
- Inherits:
-
Object
- Object
- Fintoc::Account
- Includes:
- Utils
- Defined in:
- lib/fintoc/resources/account.rb
Instance Attribute Summary collapse
-
#balance ⇒ Object
readonly
Returns the value of attribute balance.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#holder_id ⇒ Object
readonly
Returns the value of attribute holder_id.
-
#holder_name ⇒ Object
readonly
Returns the value of attribute holder_name.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#movements ⇒ Object
readonly
Returns the value of attribute movements.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#official_name ⇒ Object
readonly
Returns the value of attribute official_name.
-
#refreshed_at ⇒ Object
readonly
Returns the value of attribute refreshed_at.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #get_movements(**params) ⇒ Object
-
#initialize(id:, name:, official_name:, number:, holder_id:, holder_name:, type:, currency:, refreshed_at: nil, balance: nil, movements: nil, client: nil) ⇒ Account
constructor
A new instance of Account.
- #show_movements(rows = 5) ⇒ Object
- #to_s ⇒ Object
- #update_balance ⇒ Object
- #update_movements(**params) ⇒ Object
Methods included from Utils
#flatten, #pick, #pluralize, #snake_to_pascal
Constructor Details
#initialize(id:, name:, official_name:, number:, holder_id:, holder_name:, type:, currency:, refreshed_at: nil, balance: nil, movements: nil, client: nil) ⇒ Account
Returns a new instance of Account.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fintoc/resources/account.rb', line 11 def initialize( id:, name:, official_name:, number:, holder_id:, holder_name:, type:, currency:, refreshed_at: nil, balance: nil, movements: nil, client: nil, ** ) @id = id @name = name @official_name = official_name @number = number @holder_id = holder_id @holder_name = holder_name @type = type @currency = currency @refreshed_at = DateTime.iso8601(refreshed_at) if refreshed_at @balance = Fintoc::Balance.new(**balance) @movements = movements || [] @client = client end |
Instance Attribute Details
#balance ⇒ Object (readonly)
Returns the value of attribute balance.
9 10 11 |
# File 'lib/fintoc/resources/account.rb', line 9 def balance @balance end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
9 10 11 |
# File 'lib/fintoc/resources/account.rb', line 9 def currency @currency end |
#holder_id ⇒ Object (readonly)
Returns the value of attribute holder_id.
9 10 11 |
# File 'lib/fintoc/resources/account.rb', line 9 def holder_id @holder_id end |
#holder_name ⇒ Object (readonly)
Returns the value of attribute holder_name.
9 10 11 |
# File 'lib/fintoc/resources/account.rb', line 9 def holder_name @holder_name end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/fintoc/resources/account.rb', line 9 def id @id end |
#movements ⇒ Object (readonly)
Returns the value of attribute movements.
9 10 11 |
# File 'lib/fintoc/resources/account.rb', line 9 def movements @movements end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/fintoc/resources/account.rb', line 9 def name @name end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
9 10 11 |
# File 'lib/fintoc/resources/account.rb', line 9 def number @number end |
#official_name ⇒ Object (readonly)
Returns the value of attribute official_name.
9 10 11 |
# File 'lib/fintoc/resources/account.rb', line 9 def official_name @official_name end |
#refreshed_at ⇒ Object (readonly)
Returns the value of attribute refreshed_at.
9 10 11 |
# File 'lib/fintoc/resources/account.rb', line 9 def refreshed_at @refreshed_at end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
9 10 11 |
# File 'lib/fintoc/resources/account.rb', line 9 def type @type end |
Instance Method Details
#get_movements(**params) ⇒ Object
44 45 46 |
# File 'lib/fintoc/resources/account.rb', line 44 def get_movements(**params) _get_movements(**params).lazy.map { |movement| Fintoc::Movement.new(**movement) } end |
#show_movements(rows = 5) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/fintoc/resources/account.rb', line 53 def show_movements(rows = 5) puts("This account has #{Utils.pluralize(@movements.size, 'movement')}.") return unless @movements.any? movements = @movements.to_a.slice(0, rows) .map.with_index do |mov, index| [index + 1, mov.amount, mov.currency, mov.description, mov.locale_date] end headers = ['#', 'Amount', 'Currency', 'Description', 'Date'] puts puts tabulate(headers, movements, indent: 4, style: 'fancy') end |
#to_s ⇒ Object
67 68 69 |
# File 'lib/fintoc/resources/account.rb', line 67 def to_s "💰 #{@holder_name}’s #{@name} #{@balance}" end |
#update_balance ⇒ Object
40 41 42 |
# File 'lib/fintoc/resources/account.rb', line 40 def update_balance @balance = Fintoc::Balance.new(**get_account[:balance]) end |
#update_movements(**params) ⇒ Object
48 49 50 51 |
# File 'lib/fintoc/resources/account.rb', line 48 def update_movements(**params) @movements += get_movements(**params).to_a @movements = @movements.uniq.sort_by(&:post_date) end |