Class: Fintoc::Link
- Inherits:
-
Object
- Object
- Fintoc::Link
- Includes:
- Utils
- Defined in:
- lib/fintoc/resources/link.rb
Instance Attribute Summary collapse
-
#accounts ⇒ Object
readonly
Returns the value of attribute accounts.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#holder_type ⇒ Object
readonly
Returns the value of attribute holder_type.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#institution ⇒ Object
readonly
Returns the value of attribute institution.
-
#link_token ⇒ Object
readonly
Returns the value of attribute link_token.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #delete ⇒ Object
- #find(**kwargs) ⇒ Object
- #find_all(**kwargs) ⇒ Object
-
#initialize(id:, username:, holder_type:, institution:, created_at:, mode:, accounts: nil, link_token: nil, client: nil) ⇒ Link
constructor
A new instance of Link.
- #show_accounts(rows = 5) ⇒ Object
- #to_s ⇒ Object
- #update_accounts ⇒ Object
Methods included from Utils
#flatten, #pick, #pluralize, #snake_to_pascal
Constructor Details
#initialize(id:, username:, holder_type:, institution:, created_at:, mode:, accounts: nil, link_token: nil, client: nil) ⇒ Link
Returns a new instance of Link.
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/link.rb', line 13 def initialize( id:, username:, holder_type:, institution:, created_at:, mode:, accounts: nil, link_token: nil, client: nil, ** ) @id = id @username = username @holder_type = holder_type @institution = Fintoc::Institution.new(**institution) @created_at = Date.iso8601(created_at) @mode = mode @accounts = if accounts.nil? [] else accounts.map { |data| Fintoc::Account.new(**data, client: client) } end @token = link_token @client = client end |
Instance Attribute Details
#accounts ⇒ Object (readonly)
Returns the value of attribute accounts.
10 11 12 |
# File 'lib/fintoc/resources/link.rb', line 10 def accounts @accounts end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
10 11 12 |
# File 'lib/fintoc/resources/link.rb', line 10 def created_at @created_at end |
#holder_type ⇒ Object (readonly)
Returns the value of attribute holder_type.
10 11 12 |
# File 'lib/fintoc/resources/link.rb', line 10 def holder_type @holder_type end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/fintoc/resources/link.rb', line 10 def id @id end |
#institution ⇒ Object (readonly)
Returns the value of attribute institution.
10 11 12 |
# File 'lib/fintoc/resources/link.rb', line 10 def institution @institution end |
#link_token ⇒ Object (readonly)
Returns the value of attribute link_token.
10 11 12 |
# File 'lib/fintoc/resources/link.rb', line 10 def link_token @link_token end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
10 11 12 |
# File 'lib/fintoc/resources/link.rb', line 10 def mode @mode end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
10 11 12 |
# File 'lib/fintoc/resources/link.rb', line 10 def username @username end |
Instance Method Details
#delete ⇒ Object
75 76 77 |
# File 'lib/fintoc/resources/link.rb', line 75 def delete @client.delete_link(@id) end |
#find(**kwargs) ⇒ Object
49 50 51 52 |
# File 'lib/fintoc/resources/link.rb', line 49 def find(**kwargs) results = find_all(**kwargs) results.any? ? results.first : nil end |
#find_all(**kwargs) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/fintoc/resources/link.rb', line 40 def find_all(**kwargs) raise 'You must provide *exactly one* account field.' if kwargs.size != 1 field, value = kwargs.to_a.first @accounts.select do |account| account.send(field.to_sym) == value end end |
#show_accounts(rows = 5) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fintoc/resources/link.rb', line 54 def show_accounts(rows = 5) puts "This links has #{Utils.plurlize(@accounts.size, 'account')}" return unless @accounts.any? accounts = @accounts.to_a.slice(0, rows) .map.with_index do |acc, index| [index + 1, acc.name, acc.holder_name, account.currency] end headers = ['#', 'Name', 'Holder', 'Currency'] puts puts tabulate(headers, accounts, indent: 4, style: 'fancy') end |
#to_s ⇒ Object
79 80 81 |
# File 'lib/fintoc/resources/link.rb', line 79 def to_s "<#{@username}@#{@institution.name}> 🔗 <Fintoc>" end |
#update_accounts ⇒ Object
68 69 70 71 72 73 |
# File 'lib/fintoc/resources/link.rb', line 68 def update_accounts @accounts.each do |account| account.update_balance account.update_movements end end |