Class: TransactionFaker::User

Inherits:
Object
  • Object
show all
Defined in:
lib/transaction_faker/models/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, )
  @access_token = Faker::Lorem.characters(37)
end

Instance Attribute Details

#access_tokenObject

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

#accountObject

Returns the value of attribute account.



5
6
7
# File 'lib/transaction_faker/models/user.rb', line 5

def 
  @account
end

#transactionsObject

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.
end

#add_hash_transactionsObject



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..id,
      _id: transaction.id,
      amount: transaction.amount,
      date: transaction.date,
      name: transaction.name,
      meta: transaction.meta,
      pending: transaction.pending,
      type: transaction.type,
      category: transaction.category,
      category_id: transaction.category_id,
      score: transaction.score
    }
  end
end

#to_jsonObject



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.meta,
        type: @account.type
      }
    ],
    transactions: add_hash_transactions
  }
  JSON.pretty_generate(user_hash)
end