Class: TrangeFrange::Amount

Inherits:
Object
  • Object
show all
Defined in:
lib/trange_frange/amount.rb

Constant Summary collapse

MAX_AMOUNT_SIZE =
12
BASES =
[TrangeFrange::Hundred, TrangeFrange::Ten, TrangeFrange::One]
SUFFIXES =
[TrangeFrange::Thousand, TrangeFrange::Milion, TrangeFrange::Bilion]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount) ⇒ Amount

Returns a new instance of Amount.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/trange_frange/amount.rb', line 11

def initialize(amount)
  unless amount.is_a?(Fixnum) || amount.is_a?(Float)
    raise TypeError, 'Amount must be of type Fixnum or Float.'
  end

  if max_amount_size?(amount)
    raise NotImplementedError, 'I can only work with amounts up to 999 bilions.'
  end

  @amount = amount
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



5
6
7
# File 'lib/trange_frange/amount.rb', line 5

def amount
  @amount
end

Instance Method Details

#spell!(options = {}) ⇒ Object



23
24
25
# File 'lib/trange_frange/amount.rb', line 23

def spell!(options={})
  TrangeFrange::Shaper.new(generate_words!, fraction, options).shape!
end