Module: Baron::Shareholder

Included in:
Bank, Company, Company::MajorCompany, InitialOffering, Player, UnavailableCertificatesPool
Defined in:
lib/baron/shareholder.rb

Overview

A shareholder is someone who can hold certificates in a company. This will include things like players, companies (if the game supports companies owning their own shares, private companies, or shares in other companies), the bank pool, and the initial offering.

Instance Method Summary collapse

Instance Method Details

#add_transaction(transaction) ⇒ Array<Baron::Transaction>

Adds a transaction to this shareholder

has participated in

Examples:

shareholder.add_transaction(transaction)
# adds the transaction to the list of transactions, then
# returns all transactions for this shareholder

Parameters:

Returns:


119
120
121
# File 'lib/baron/shareholder.rb', line 119

def add_transaction(transaction)
  transactions.push transaction
end

#balanceMoney

The current amount of money that this shareholder has

Examples:

shareholder.balance
# returns the amount of money they currently have

Returns:

  • (Money)

    The total amount of money this sharehold currently has


16
17
18
# File 'lib/baron/shareholder.rb', line 16

def balance
  money_total(:credits) - money_total(:debits)
end

#certificatesArray<Baron::Certificate>

The certificates this shareholder currently has

Examples:

shareholder.certificates

Returns:


27
28
29
# File 'lib/baron/shareholder.rb', line 27

def certificates
  currently_owned(Transaction::IS_CERTIFICATE)
end

#certificates_for(company) ⇒ Array<Baron::Certificate>

Returns all of the certificates for the matching company

company. If the sharholder has no certificates, then an empty array will be returned

Examples:

sharholder.certificates_for(company)

Returns:


63
64
65
66
67
# File 'lib/baron/shareholder.rb', line 63

def certificates_for(company)
  certificates.select do |cert|
    cert.company.equal? company
  end
end

#directorshipsArray<Baron::Company>

Return the companies that this shareholder is a director of

the director of. If the player is not a director of any companies it will be an empty array.

Examples:

shareholder.directorships

Returns:


90
91
92
# File 'lib/baron/shareholder.rb', line 90

def directorships
  certificates.select(&:director?).map(&:company)
end

#give(shareholder, transferrable) ⇒ Baron::Transaction

Give the shareholder the transferrable item at no cost

Examples:

bank.give(shareholder, Baron::Money.new(10))

Parameters:

Returns:


132
133
134
# File 'lib/baron/shareholder.rb', line 132

def give(shareholder, transferrable)
  Transaction.new shareholder, Array(transferrable), self, []
end

#grant(transferrable) ⇒ Baron::Transaction

Get the transferrable item from no recipient

This should not generally be used in the course of the normal game, as money will move between the bank, and players. However, to set the game up, the bank money needs to come from somewhere. Therefore, we can grant something to come from no source.

can also take in an array of Transferrable objects

Examples:

bank.grant(Baron::Money.new(12_000))

Parameters:

Returns:


150
151
152
# File 'lib/baron/shareholder.rb', line 150

def grant(transferrable)
  Transaction.new self, Array(transferrable), nil, []
end

#largest_trainFixnum

The largest train by major station allowance

allowed to hit. nil if the company has no trains

Examples:

shareholder.largest_train

Returns:

  • (Fixnum)

    The number of major stations the largest train is


50
51
52
# File 'lib/baron/shareholder.rb', line 50

def largest_train
  trains.map { |train| train.type.major_station_allowance }.max
end

#percentage_owned(company) ⇒ BigDecimal

Returns the percentage of the company by this sharedholder

shareholder. If this shareholder owns no shares, then 0 is returned.

Examples:

shareholder.percentage_owned(company)

Returns:

  • (BigDecimal)

    The percantage of this company owned by the


77
78
79
# File 'lib/baron/shareholder.rb', line 77

def percentage_owned(company)
  certificates_for(company).map(&:portion).inject(:+) || 0
end

#private_certificatesArray<Baron::Company::PrivateCompany>

Return the private companies that this shareholder currently owns

that this shareholder currently owns

Examples:

shareholder.private_companies

Returns:


102
103
104
105
106
# File 'lib/baron/shareholder.rb', line 102

def private_certificates
  certificates.select do |cert|
    cert.company.instance_of? Company::PrivateCompany
  end
end

#trainsArray<Baron::Train>

The trains this shareholder currently has

Examples:

shareholder.trains

Returns:


38
39
40
# File 'lib/baron/shareholder.rb', line 38

def trains
  currently_owned(Transaction::IS_TRAIN)
end