Class: Wordify::Token::Unit

Inherits:
Object
  • Object
show all
Defined in:
lib/wordify/token/unit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#characterObject (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: ==

Returns:

  • (Boolean)


28
29
30
# File 'lib/wordify/token/unit.rb', line 28

def eql?(other)
  character == other.character
end

#numberObject



7
8
9
# File 'lib/wordify/token/unit.rb', line 7

def number
  point? ? nil : character.to_i
end

#point?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/wordify/token/unit.rb', line 11

def point?
  character == '.'
end

#unitObject 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

Returns:

  • (Boolean)


15
16
17
# File 'lib/wordify/token/unit.rb', line 15

def unit?
  not point?
end

#zero?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/wordify/token/unit.rb', line 19

def zero?
  character == '0'
end