Class: BeanSprout::Bean

Inherits:
Object
  • Object
show all
Includes:
PackagePrivate::InternalClass
Defined in:
lib/bean_sprout/account.rb

Overview

TODO: abstract :id?

Instance Attribute Summary collapse

Attributes included from PackagePrivate::InternalClass

#public_interface

Instance Method Summary collapse

Methods included from PackagePrivate::InternalClass

#bind_public_interface, included

Constructor Details

#initialize(id, currency) ⇒ Bean



12
13
14
15
16
17
18
# File 'lib/bean_sprout/account.rb', line 12

def initialize id, currency
  @id = id
  @currency = currency

  @sprouts = Set.new
  @balance = 0
end

Instance Attribute Details

#balanceObject (readonly)

Returns the value of attribute balance.



8
9
10
# File 'lib/bean_sprout/account.rb', line 8

def balance
  @balance
end

#currencyObject (readonly)

Returns the value of attribute currency.



8
9
10
# File 'lib/bean_sprout/account.rb', line 8

def currency
  @currency
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/bean_sprout/account.rb', line 8

def id
  @id
end

#sproutsObject (readonly)

Returns the value of attribute sprouts.



8
9
10
# File 'lib/bean_sprout/account.rb', line 8

def sprouts
  @sprouts
end

Instance Method Details

#grow(sprout) ⇒ Object



20
21
22
23
# File 'lib/bean_sprout/account.rb', line 20

def grow sprout
  @sprouts.add sprout
  @balance += sprout.amount
end

#pick(sprout) ⇒ Object



25
26
27
28
# File 'lib/bean_sprout/account.rb', line 25

def pick sprout
  @sprouts.delete sprout
  @balance -= sprout.amount
end