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]
LETTER_TO_TYPE =
{
    'A' => ASSET,
    'L' => LIABILITY,
    'O' => EQUITY,
    'I' => INCOME,
    'E' => EXPENSE
}
SYMBOL_TO_TYPE =
{
    :asset => ASSET,
    :liability => LIABILITY,
    :equity => EQUITY,
    :income => INCOME,
    :expense => 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

.letter_to_type(string) ⇒ Object

Converts type upper case letter representation to a type object (e.g. ‘A’ => ASSET)



32
33
34
35
36
37
38
# File 'lib/rock_books/types/account_type.rb', line 32

def self.letter_to_type(string)
  key = string[0].upcase
  LETTER_TO_TYPE.fetch(key) do
    raise Error.new("Account type of #{string} not valid. " +
        "Must be one of #{LETTER_TO_TYPE.keys} (#{ALL_TYPES.map(&:singular_name)})")
  end
end

.symbol_to_type(symbol) ⇒ Object



40
41
42
# File 'lib/rock_books/types/account_type.rb', line 40

def self.symbol_to_type(symbol)
  SYMBOL_TO_TYPE[symbol]
end