Class: Baron::Certificate

Inherits:
Object
  • Object
show all
Includes:
Ownable
Defined in:
lib/baron/certificate.rb

Overview

A certificate represents a portion of ownership in a company.

This entitlesthe owner to certain privileges including payment of dividends. Players are generally limited on the number of certificates that they can own at any given time.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Ownable

#owner, #owner=, #validate_owner

Methods included from Transferrable

#owner=, #validate_owner

Constructor Details

#initialize(company, portion) ⇒ Certificate

Initialize the certificate

Examples:

Baron::Certificate(company, BigDecimal.new('0.20'))

Parameters:

  • company (Company)
  • portion (BigDecimal)

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

def initialize(company, portion)
  @company = company
  @portion = portion
end

Instance Attribute Details

#companyObject (readonly)

The company which this certificate is for

Examples:

certificate.company

Returns:

  • Baron::Company


18
19
20
# File 'lib/baron/certificate.rb', line 18

def company
  @company
end

#portionObject (readonly)

The portion of the company this share is for

Examples:

certificate.portion

Returns:

  • BigDecimal


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

def portion
  @portion
end

Instance Method Details

#controlling?Boolean

Returns whether this is a controlling certificate

A controlling certificate is a directors certificate of a major company, or a single certificate of a private company.

Examples:

certificate.controlling? #=> true

Returns:

  • (Boolean)

    True if this is a controlling certificate


52
53
54
# File 'lib/baron/certificate.rb', line 52

def controlling?
  portion.eql?(1) || director?
end

#director?Boolean

Returns whether this is a directors certificate

otherwise

Examples:

certificate.director? #=> true

Returns:

  • (Boolean)

    True if this is a director's certificate, false


64
65
66
# File 'lib/baron/certificate.rb', line 64

def director?
  num_shares.equal? 2
end

#inspectString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return a string representation of the player

Returns:

  • (String)

103
104
105
# File 'lib/baron/certificate.rb', line 103

def inspect
  "#<Baron::Certificiate:#{object_id} #{company} @ #{portion.to_f}>"
end

#market_cost(market) ⇒ Baron::Money

The market cost of the current certificate

Examples:

certificate.market_cost(market)

Parameters:

Returns:


95
96
97
# File 'lib/baron/certificate.rb', line 95

def market_cost(market)
  market.price(company) * num_shares
end

#num_sharesFixnum

Returns the number of shares that this certificate provides

For a standard 10 share major company, this will be 2 shares for the directors certificate, and 1 share for all others.

Examples:

Baron::Certificate(company, BigDecimal.new('0.20')).num_shares #=> 2

Returns:

  • (Fixnum)

    The number of shares this represents.


78
79
80
81
82
83
84
85
# File 'lib/baron/certificate.rb', line 78

def num_shares
  case portion
  when BigDecimal.new('0.2')
    2
  else
    1
  end
end