Class: Fintoc::V1::Account
- Inherits:
-
Object
- Object
- Fintoc::V1::Account
- Includes:
- Utils
- Defined in:
- lib/fintoc/v1/resources/account.rb
Constant Summary collapse
- HEADERS =
['#', 'Amount', 'Currency', 'Description', 'Date'].freeze
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.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fintoc/v1/resources/account.rb', line 16 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::V1::Balance.new(**balance) @movements = movements || [] @client = client end |
Instance Attribute Details
#balance ⇒ Object (readonly)
Returns the value of attribute balance.
11 12 13 |
# File 'lib/fintoc/v1/resources/account.rb', line 11 def balance @balance end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
11 12 13 |
# File 'lib/fintoc/v1/resources/account.rb', line 11 def currency @currency end |
#holder_id ⇒ Object (readonly)
Returns the value of attribute holder_id.
11 12 13 |
# File 'lib/fintoc/v1/resources/account.rb', line 11 def holder_id @holder_id end |
#holder_name ⇒ Object (readonly)
Returns the value of attribute holder_name.
11 12 13 |
# File 'lib/fintoc/v1/resources/account.rb', line 11 def holder_name @holder_name end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'lib/fintoc/v1/resources/account.rb', line 11 def id @id end |
#movements ⇒ Object (readonly)
Returns the value of attribute movements.
11 12 13 |
# File 'lib/fintoc/v1/resources/account.rb', line 11 def movements @movements end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/fintoc/v1/resources/account.rb', line 11 def name @name end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
11 12 13 |
# File 'lib/fintoc/v1/resources/account.rb', line 11 def number @number end |
#official_name ⇒ Object (readonly)
Returns the value of attribute official_name.
11 12 13 |
# File 'lib/fintoc/v1/resources/account.rb', line 11 def official_name @official_name end |
#refreshed_at ⇒ Object (readonly)
Returns the value of attribute refreshed_at.
11 12 13 |
# File 'lib/fintoc/v1/resources/account.rb', line 11 def refreshed_at @refreshed_at end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
11 12 13 |
# File 'lib/fintoc/v1/resources/account.rb', line 11 def type @type end |
Instance Method Details
#get_movements(**params) ⇒ Object
49 50 51 52 53 |
# File 'lib/fintoc/v1/resources/account.rb', line 49 def get_movements(**params) _get_movements(**params).lazy.map do |movement| Fintoc::V1::Movement.new(**movement, client: @client) end end |
#show_movements(rows = 5) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fintoc/v1/resources/account.rb', line 60 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 puts puts tabulate(HEADERS, movements, indent: 4, style: 'fancy') end |
#to_s ⇒ Object
77 78 79 |
# File 'lib/fintoc/v1/resources/account.rb', line 77 def to_s "💰 #{@holder_name}’s #{@name} #{@balance}" end |
#update_balance ⇒ Object
45 46 47 |
# File 'lib/fintoc/v1/resources/account.rb', line 45 def update_balance @balance = Fintoc::V1::Balance.new(**get_account[:balance]) end |
#update_movements(**params) ⇒ Object
55 56 57 58 |
# File 'lib/fintoc/v1/resources/account.rb', line 55 def update_movements(**params) @movements += get_movements(**params).to_a @movements = @movements.uniq.sort_by(&:post_date) end |