Class: NumberNameString::Triplet

Inherits:
Object
  • Object
show all
Defined in:
lib/number_name_string/triplet.rb

Overview

Accumulates and totals a 3 digit number (with an optional scale) Used internally only.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(num = 0) ⇒ Triplet

Returns a new instance of Triplet.



7
8
9
# File 'lib/number_name_string/triplet.rb', line 7

def initialize(num = 0)
  reset num
end

Instance Attribute Details

#hundredsObject

Returns the value of attribute hundreds.



5
6
7
# File 'lib/number_name_string/triplet.rb', line 5

def hundreds
  @hundreds
end

#scaleObject

Returns the value of attribute scale.



5
6
7
# File 'lib/number_name_string/triplet.rb', line 5

def scale
  @scale
end

#tensObject

Returns the value of attribute tens.



5
6
7
# File 'lib/number_name_string/triplet.rb', line 5

def tens
  @tens
end

Instance Method Details

#<<(num) ⇒ Object



11
12
13
14
# File 'lib/number_name_string/triplet.rb', line 11

def <<(num)
  @hundreds = @tens if @tens > 0
  @tens = num % 100
end

#reset(num = 0) ⇒ Object



20
21
22
23
24
# File 'lib/number_name_string/triplet.rb', line 20

def reset(num = 0)
  @hundreds = 0
  @tens = num
  @scale = 1
end

#to_iObject



16
17
18
# File 'lib/number_name_string/triplet.rb', line 16

def to_i
  (@hundreds * 100 + @tens) * @scale 
end