Class: Wordify::Token::Unit
- Inherits:
-
Object
- Object
- Wordify::Token::Unit
- Defined in:
- lib/wordify/token/unit.rb
Instance Attribute Summary collapse
-
#character ⇒ Object
readonly
Returns the value of attribute character.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
-
#initialize(char) ⇒ Unit
constructor
A new instance of Unit.
- #number ⇒ Object
- #point? ⇒ Boolean
- #unit ⇒ Object (also: #to_s)
- #unit? ⇒ Boolean
- #zero? ⇒ Boolean
Constructor Details
#initialize(char) ⇒ Unit
Returns a new instance of Unit.
3 4 5 |
# File 'lib/wordify/token/unit.rb', line 3 def initialize(char) @character = char end |
Instance Attribute Details
#character ⇒ Object (readonly)
Returns the value of attribute character.
2 3 4 |
# File 'lib/wordify/token/unit.rb', line 2 def character @character end |
Instance Method Details
#<=>(other) ⇒ Object
33 34 35 |
# File 'lib/wordify/token/unit.rb', line 33 def <=>(other) character <=> other.character end |
#eql?(other) ⇒ Boolean Also known as: ==
28 29 30 |
# File 'lib/wordify/token/unit.rb', line 28 def eql?(other) character == other.character end |
#number ⇒ Object
7 8 9 |
# File 'lib/wordify/token/unit.rb', line 7 def number point? ? nil : character.to_i end |
#point? ⇒ Boolean
11 12 13 |
# File 'lib/wordify/token/unit.rb', line 11 def point? character == '.' end |
#unit ⇒ Object Also known as: to_s
23 24 25 |
# File 'lib/wordify/token/unit.rb', line 23 def unit @unit ||= point? ? 'point' : Wordify.units[character.to_i] end |
#unit? ⇒ Boolean
15 16 17 |
# File 'lib/wordify/token/unit.rb', line 15 def unit? not point? end |
#zero? ⇒ Boolean
19 20 21 |
# File 'lib/wordify/token/unit.rb', line 19 def zero? character == '0' end |