Class: Percentage

Inherits:
Object
  • Object
show all
Defined in:
lib/alea/percentage.rb

Defined Under Namespace

Classes: Chance

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount) ⇒ Percentage

Returns a new instance of Percentage.



3
4
5
# File 'lib/alea/percentage.rb', line 3

def initialize(amount)
  @amount = amount
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



2
3
4
# File 'lib/alea/percentage.rb', line 2

def amount
  @amount
end

Instance Method Details

#chanceObject



7
8
9
# File 'lib/alea/percentage.rb', line 7

def chance
  Chance.new(self)
end

#of(number, rounded = true) ⇒ Object



11
12
13
14
# File 'lib/alea/percentage.rb', line 11

def of(number, rounded=true)
  p = number * amount / 100.0
  rounded ? p.round : p
end