Class: RockBooks::AccountType

Inherits:
Struct
  • Object
show all
Defined in:
lib/rock_books/types/account_type.rb

Constant Summary collapse

ASSET =
self.new(:asset,      'Asset',      'Assets')
LIABILITY =
self.new(:liability,  'Liability',  'Liabilities')
EQUITY =
self.new(:equity,     'Equity',     'Equity')
INCOME =
self.new(:income,     'Income',     'Income')
EXPENSE =
self.new(:expense,    'Expense',    'Expenses')
ALL_TYPES =
[ASSET, LIABILITY, EQUITY, INCOME, EXPENSE]
TYPE_HASH =
{
    'A' => ASSET,
    'L' => LIABILITY,
    'O' => EQUITY,
    'I' => INCOME,
    'E' => EXPENSE
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#plural_nameObject

Returns the value of attribute plural_name

Returns:

  • (Object)

    the current value of plural_name



5
6
7
# File 'lib/rock_books/types/account_type.rb', line 5

def plural_name
  @plural_name
end

#singular_nameObject

Returns the value of attribute singular_name

Returns:

  • (Object)

    the current value of singular_name



5
6
7
# File 'lib/rock_books/types/account_type.rb', line 5

def singular_name
  @singular_name
end

#symbolObject

Returns the value of attribute symbol

Returns:

  • (Object)

    the current value of symbol



5
6
7
# File 'lib/rock_books/types/account_type.rb', line 5

def symbol
  @symbol
end

Class Method Details

.to_type(string) ⇒ Object

Converts strings



24
25
26
27
28
29
30
31
# File 'lib/rock_books/types/account_type.rb', line 24

def self.to_type(string)
  type = TYPE_HASH[string[0].upcase]
  if type.nil?
    raise Error.new("Account type of #{string} not valid. " +
        "Must be one of #{TYPE_HASH.keys} (#{ALL_TYPES.map(&:singular_name)})")
  end
  type
end