Class: LendingClub::Portfolio

Inherits:
Object
  • Object
show all
Defined in:
lib/lending_club/client/portfolio.rb

Constant Summary collapse

ATTRIBUTES =
[
  :portfolio_id,
  :portfolio_name,
  :portfolio_description
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_hash) ⇒ Portfolio

Returns a new instance of Portfolio.



19
20
21
22
23
24
25
# File 'lib/lending_club/client/portfolio.rb', line 19

def initialize(data_hash)
  @portfolio_id = Integer(data_hash['portfolioId'])
  @portfolio_name = data_hash['portfolioName'].to_s
  if data_hash['portfolioDescription']
    @portfolio_description = data_hash['portfolioDescription'].to_s
  end
end

Instance Attribute Details

#portfolio_descriptionString? (readonly)

Returns Portfolio description.

Returns:

  • (String, nil)

    Portfolio description



17
18
19
# File 'lib/lending_club/client/portfolio.rb', line 17

def portfolio_description
  @portfolio_description
end

#portfolio_idInteger (readonly)

Returns Portfolio Id.

Returns:

  • (Integer)

    Portfolio Id



13
14
15
# File 'lib/lending_club/client/portfolio.rb', line 13

def portfolio_id
  @portfolio_id
end

#portfolio_nameString (readonly)

Returns Portfolio name.

Returns:

  • (String)

    Portfolio name



15
16
17
# File 'lib/lending_club/client/portfolio.rb', line 15

def portfolio_name
  @portfolio_name
end

Class Method Details

.collection(data_hash) ⇒ Object



27
28
29
30
31
32
# File 'lib/lending_club/client/portfolio.rb', line 27

def self.collection(data_hash)
  return [] unless data_hash['myPortfolios']
  data_hash['myPortfolios'].map do |portfolio|
    new(portfolio)
  end
end

Instance Method Details

#to_hObject



34
35
36
37
38
39
# File 'lib/lending_club/client/portfolio.rb', line 34

def to_h
  ATTRIBUTES.reduce({}) do |h, attribute|
    h[attribute.to_s] = send(attribute)
    h
  end
end