Class: NumberNameString::Triplet
- Inherits:
-
Object
- Object
- NumberNameString::Triplet
- 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
-
#hundreds ⇒ Object
Returns the value of attribute hundreds.
-
#scale ⇒ Object
Returns the value of attribute scale.
-
#tens ⇒ Object
Returns the value of attribute tens.
Instance Method Summary collapse
- #<<(num) ⇒ Object
-
#initialize(num = 0) ⇒ Triplet
constructor
A new instance of Triplet.
- #reset(num = 0) ⇒ Object
- #to_i ⇒ Object
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
#hundreds ⇒ Object
Returns the value of attribute hundreds.
5 6 7 |
# File 'lib/number_name_string/triplet.rb', line 5 def hundreds @hundreds end |
#scale ⇒ Object
Returns the value of attribute scale.
5 6 7 |
# File 'lib/number_name_string/triplet.rb', line 5 def scale @scale end |
#tens ⇒ Object
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_i ⇒ Object
16 17 18 |
# File 'lib/number_name_string/triplet.rb', line 16 def to_i (@hundreds * 100 + @tens) * @scale end |