Class: Wordify::Token::Hundreds
- Inherits:
-
Object
- Object
- Wordify::Token::Hundreds
- Defined in:
- lib/wordify/token/hundreds.rb
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #group ⇒ Object
- #hundreds ⇒ Object
-
#initialize(string) ⇒ Hundreds
constructor
A new instance of Hundreds.
- #raw_tokens ⇒ Object
- #size ⇒ Object
- #tens ⇒ Object
- #to_s ⇒ Object
- #tokens ⇒ Object
Constructor Details
#initialize(string) ⇒ Hundreds
Returns a new instance of Hundreds.
3 4 5 |
# File 'lib/wordify/token/hundreds.rb', line 3 def initialize(string) @string, @number = string, string.to_i end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
2 3 4 |
# File 'lib/wordify/token/hundreds.rb', line 2 def number @number end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
2 3 4 |
# File 'lib/wordify/token/hundreds.rb', line 2 def string @string end |
Instance Method Details
#<=>(other) ⇒ Object
41 42 43 |
# File 'lib/wordify/token/hundreds.rb', line 41 def <=>(other) to_s <=> other.to_s end |
#eql?(other) ⇒ Boolean Also known as: ==
36 37 38 |
# File 'lib/wordify/token/hundreds.rb', line 36 def eql?(other) to_s == other.to_s end |
#group ⇒ Object
27 28 29 |
# File 'lib/wordify/token/hundreds.rb', line 27 def group @group ||= [hundreds, tens].compact end |
#hundreds ⇒ Object
19 20 21 |
# File 'lib/wordify/token/hundreds.rb', line 19 def hundreds tokens[0].zero? ? nil : "#{tokens[0].unit} hundred" end |
#raw_tokens ⇒ Object
7 8 9 |
# File 'lib/wordify/token/hundreds.rb', line 7 def raw_tokens @raw_tokens ||= string.scan(/[0-9]/).map { |t| Wordify::Token::Unit.new(t) } end |
#size ⇒ Object
15 16 17 |
# File 'lib/wordify/token/hundreds.rb', line 15 def size tokens.size end |
#tens ⇒ Object
23 24 25 |
# File 'lib/wordify/token/hundreds.rb', line 23 def tens Wordify::Token::Tens.new(tokens[1], tokens[2]).to_s end |
#to_s ⇒ Object
31 32 33 34 |
# File 'lib/wordify/token/hundreds.rb', line 31 def to_s return nil if number.zero? group.any? ? group.join(' and ') : nil end |