Class: Wordify::Token::Tens
- Inherits:
-
Object
- Object
- Wordify::Token::Tens
- Defined in:
- lib/wordify/token/tens.rb
Instance Attribute Summary collapse
-
#tens ⇒ Object
readonly
Returns the value of attribute tens.
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
-
#initialize(*unit_tokens) ⇒ Tens
constructor
A new instance of Tens.
- #teen? ⇒ Boolean
- #ten? ⇒ Boolean
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(*unit_tokens) ⇒ Tens
Returns a new instance of Tens.
3 4 5 6 |
# File 'lib/wordify/token/tens.rb', line 3 def initialize(*unit_tokens) @tens, @unit = unit_tokens raise StandardError, 'Invalid tokens' unless valid? end |
Instance Attribute Details
#tens ⇒ Object (readonly)
Returns the value of attribute tens.
2 3 4 |
# File 'lib/wordify/token/tens.rb', line 2 def tens @tens end |
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
2 3 4 |
# File 'lib/wordify/token/tens.rb', line 2 def unit @unit end |
Instance Method Details
#<=>(other) ⇒ Object
38 39 40 |
# File 'lib/wordify/token/tens.rb', line 38 def <=>(other) to_s <=> other.to_s end |
#eql?(other) ⇒ Boolean Also known as: ==
33 34 35 |
# File 'lib/wordify/token/tens.rb', line 33 def eql?(other) to_s == other.to_s end |
#teen? ⇒ Boolean
12 13 14 |
# File 'lib/wordify/token/tens.rb', line 12 def teen? tens.number == 1 end |
#ten? ⇒ Boolean
8 9 10 |
# File 'lib/wordify/token/tens.rb', line 8 def ten? tens.number > 1 end |
#to_s ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/wordify/token/tens.rb', line 20 def to_s chars = [] if ten? chars << Wordify.tens[tens.number] chars << unit.unit unless unit.zero? elsif teen? chars << Wordify.teens[unit.number] else chars << unit.unit unless unit.zero? end chars.any? ? chars.join(' ') : nil end |