Class: SchwabRb::AccountHashManager

Inherits:
Object
  • Object
show all
Defined in:
lib/schwab_rb/account_hash_manager.rb

Defined Under Namespace

Classes: AccountNamesFileNotFoundError, InvalidAccountNamesFileError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(account_names_path = nil, account_hashes_path = nil) ⇒ AccountHashManager

Returns a new instance of AccountHashManager.



13
14
15
16
17
18
19
# File 'lib/schwab_rb/account_hash_manager.rb', line 13

def initialize( = nil,  = nil)
  @account_names_path =  || SchwabRb.configuration.
  @account_hashes_path =  || SchwabRb.configuration.
  @account_names_path = File.expand_path(@account_names_path)
  @account_hashes_path = File.expand_path(@account_hashes_path)
  @account_names = []
end

Instance Attribute Details

#account_hashes_pathObject (readonly)

Returns the value of attribute account_hashes_path.



11
12
13
# File 'lib/schwab_rb/account_hash_manager.rb', line 11

def 
  @account_hashes_path
end

#account_namesObject (readonly)

Returns the value of attribute account_names.



11
12
13
# File 'lib/schwab_rb/account_hash_manager.rb', line 11

def 
  @account_names
end

#account_names_pathObject (readonly)

Returns the value of attribute account_names_path.



11
12
13
# File 'lib/schwab_rb/account_hash_manager.rb', line 11

def 
  @account_names_path
end

Instance Method Details

#available_account_namesObject



71
72
73
74
75
76
77
# File 'lib/schwab_rb/account_hash_manager.rb', line 71

def 
  begin
    .keys
  rescue AccountNamesFileNotFoundError
    []
  end
end

#get_all_hashesObject



67
68
69
# File 'lib/schwab_rb/account_hash_manager.rb', line 67

def get_all_hashes
  
end

#get_hash_by_name(account_name) ⇒ Object



62
63
64
65
# File 'lib/schwab_rb/account_hash_manager.rb', line 62

def get_hash_by_name()
  hashes = 
  hashes[]
end

#update_hashes_from_api_response(account_numbers_response) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/schwab_rb/account_hash_manager.rb', line 21

def update_hashes_from_api_response()
   = 
  current_hashes = 

  number_to_hash = {}
  .each do ||
     = [:accountNumber]
    hash_value = [:hashValue]
    number_to_hash[] = hash_value
  end

  updated_hashes = {}
  missing_accounts = []

  .each do |name, |
    if number_to_hash.key?()
      updated_hashes[name] = number_to_hash[]
    elsif current_hashes.key?(name)
      # Keep existing hash but warn that account wasn't in API response
      updated_hashes[name] = current_hashes[name]
      missing_accounts << { name: name, number:  }
    else
      # Account name exists but no hash found (new or invalid account)
      missing_accounts << { name: name, number:  }
    end
  end

  # Log warnings for accounts that weren't found in API response
  if missing_accounts.any?
    missing_accounts.each do ||
      SchwabRb::Logger.logger.warn(
        "Account '#{account[:name]}' (#{account[:number]}) not found in API response. " \
        "This may indicate a closed account or incorrect account number in account_names.json"
      )
    end
  end

  (updated_hashes)
  updated_hashes
end