Class: SchwabRb::DataObjects::UserPreferences

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

Defined Under Namespace

Classes: Offer, StreamerInfo, UserAccount

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ UserPreferences

Returns a new instance of UserPreferences.



14
15
16
17
18
# File 'lib/schwab_rb/data_objects/user_preferences.rb', line 14

def initialize(data)
  @accounts = data[:accounts]&.map { || UserAccount.new() } || []
  @streamer_info = data[:streamerInfo]&.map { |streamer_data| StreamerInfo.new(streamer_data) } || []
  @offers = data[:offers]&.map { |offer_data| Offer.new(offer_data) } || []
end

Instance Attribute Details

#accountsObject (readonly)

Returns the value of attribute accounts.



6
7
8
# File 'lib/schwab_rb/data_objects/user_preferences.rb', line 6

def accounts
  @accounts
end

#offersObject (readonly)

Returns the value of attribute offers.



6
7
8
# File 'lib/schwab_rb/data_objects/user_preferences.rb', line 6

def offers
  @offers
end

#streamer_infoObject (readonly)

Returns the value of attribute streamer_info.



6
7
8
# File 'lib/schwab_rb/data_objects/user_preferences.rb', line 6

def streamer_info
  @streamer_info
end

Class Method Details

.build(data) ⇒ Object



9
10
11
# File 'lib/schwab_rb/data_objects/user_preferences.rb', line 9

def build(data)
  new(data)
end

Instance Method Details

#account_numbersObject



36
37
38
# File 'lib/schwab_rb/data_objects/user_preferences.rb', line 36

def 
  @accounts.map(&:account_number)
end

#brokerage_accountsObject



40
41
42
# File 'lib/schwab_rb/data_objects/user_preferences.rb', line 40

def brokerage_accounts
  @accounts.select { || .type == "BROKERAGE" }
end

#find_account_by_number(account_number) ⇒ Object



32
33
34
# File 'lib/schwab_rb/data_objects/user_preferences.rb', line 32

def ()
  @accounts.find { || . ==  }
end

#has_level2_permissions?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/schwab_rb/data_objects/user_preferences.rb', line 44

def has_level2_permissions?
  @offers.any?(&:level2_permissions?)
end

#primary_accountObject



28
29
30
# File 'lib/schwab_rb/data_objects/user_preferences.rb', line 28

def 
  @accounts.find(&:primary_account?)
end

#to_hObject



20
21
22
23
24
25
26
# File 'lib/schwab_rb/data_objects/user_preferences.rb', line 20

def to_h
  {
    accounts: @accounts.map(&:to_h),
    streamerInfo: @streamer_info.map(&:to_h),
    offers: @offers.map(&:to_h)
  }
end