Class: TransactionFaker::User
- Inherits:
-
Object
- Object
- TransactionFaker::User
- Defined in:
- lib/transaction_faker/models/user.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#account ⇒ Object
Returns the value of attribute account.
-
#transactions ⇒ Object
Returns the value of attribute transactions.
Instance Method Summary collapse
- #==(other_user) ⇒ Object
- #add_hash_transactions ⇒ Object
-
#initialize(available_balance, current_balance, transaction_hash, seed = nil) ⇒ User
constructor
A new instance of User.
- #to_json ⇒ Object
Constructor Details
#initialize(available_balance, current_balance, transaction_hash, seed = nil) ⇒ User
Returns a new instance of User.
7 8 9 10 11 12 |
# File 'lib/transaction_faker/models/user.rb', line 7 def initialize(available_balance, current_balance, transaction_hash, seed = nil) srand(seed) if seed @account = Account.new(available_balance, current_balance) @transactions = TransactionHelper::create_transactions(transaction_hash, account) @access_token = Faker::Lorem.characters(37) end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
5 6 7 |
# File 'lib/transaction_faker/models/user.rb', line 5 def access_token @access_token end |
#account ⇒ Object
Returns the value of attribute account.
5 6 7 |
# File 'lib/transaction_faker/models/user.rb', line 5 def account @account end |
#transactions ⇒ Object
Returns the value of attribute transactions.
5 6 7 |
# File 'lib/transaction_faker/models/user.rb', line 5 def transactions @transactions end |
Instance Method Details
#==(other_user) ⇒ Object
14 15 16 |
# File 'lib/transaction_faker/models/user.rb', line 14 def ==(other_user) @account == other_user.account end |
#add_hash_transactions ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/transaction_faker/models/user.rb', line 39 def add_hash_transactions @transactions.map do |transaction| { _account: transaction.account.id, _id: transaction.id, amount: transaction.amount, date: transaction.date, name: transaction.name, meta: transaction., pending: transaction.pending, type: transaction.type, category: transaction.category, category_id: transaction.category_id, score: transaction.score } end end |
#to_json ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/transaction_faker/models/user.rb', line 18 def to_json user_hash = { accounts: [ { _id: @account.id, _item: @account.item, _user: @account.user, balance: { available: @account.balance["available"], current: @account.balance["current"] }, institution_type: @account.institution_type, meta: @account., type: @account.type } ], transactions: add_hash_transactions } JSON.pretty_generate(user_hash) end |