Class: StringToNumber::ToNumber
- Inherits:
-
Object
- Object
- StringToNumber::ToNumber
- Defined in:
- lib/string_to_number/to_number.rb
Constant Summary collapse
- EXCEPTIONS =
{ 'zéro' => 0, 'zero' => 0, 'un' => 1, 'deux' => 2, 'trois' => 3, 'quatre' => 4, 'cinq' => 5, 'six' => 6, 'sept' => 7, 'huit' => 8, 'neuf' => 9, 'dix' => 10, 'onze' => 11, 'douze' => 12, 'treize' => 13, 'quatorze' => 14, 'quinze' => 15, 'seize' => 16, 'dix-sept' => 17, 'dix-huit' => 18, 'dix-neuf' => 19, 'vingt' => 20, 'trente' => 30, 'quarante' => 40, 'cinquante' => 50, 'soixante' => 60, 'soixante-dix' => 70, 'quatre-vingts' => 80, 'quatre-vingt' => 80, 'quatre-vingt-dix' => 90, 'quatre-vingts-dix' => 90 }.freeze
- POWERS_OF_TEN =
{ 'un' => 0, 'dix' => 1, 'cent' => 2, 'mille' => 3, 'million' => 6, 'billion' => 9, 'trillion' => 12, 'quadrillion' => 15, 'quintillion' => 18, 'sextillion' => 21, 'septillion' => 24, 'octillion' => 27, 'nonillion' => 30, 'decillion' => 33, 'undecillion' => 36, 'duodecillion' => 39, 'tredecillion' => 42, 'quattuordecillion' => 45, 'quindecillion' => 48, 'sexdecillion' => 51, 'septendecillion' => 54, 'octodecillion' => 57, 'novemdecillion' => 60, 'vigintillion' => 63, 'unvigintillion' => 66, 'duovigintillion' => 69, 'trevigintillion' => 72, 'quattuorvigintillion' => 75, 'quinvigintillion' => 78, 'sexvigintillion' => 81, 'septenvigintillion' => 84, 'octovigintillion' => 87, 'novemvigintillion' => 90, 'trigintillion' => 93, 'untrigintillion' => 96, 'duotrigintillion' => 99, 'googol' => 100 }.freeze
Instance Attribute Summary collapse
-
#keys ⇒ Object
Returns the value of attribute keys.
-
#sentence ⇒ Object
Returns the value of attribute sentence.
Instance Method Summary collapse
-
#initialize(sentence = '') ⇒ ToNumber
constructor
A new instance of ToNumber.
- #to_number ⇒ Object
Constructor Details
#initialize(sentence = '') ⇒ ToNumber
Returns a new instance of ToNumber.
81 82 83 84 |
# File 'lib/string_to_number/to_number.rb', line 81 def initialize(sentence = '') @keys = POWERS_OF_TEN.keys.reject { |k| %w[un dix].include?(k) }.join('|') @sentence = sentence end |
Instance Attribute Details
#keys ⇒ Object
Returns the value of attribute keys.
5 6 7 |
# File 'lib/string_to_number/to_number.rb', line 5 def keys @keys end |
#sentence ⇒ Object
Returns the value of attribute sentence.
5 6 7 |
# File 'lib/string_to_number/to_number.rb', line 5 def sentence @sentence end |
Instance Method Details
#to_number ⇒ Object
86 87 88 |
# File 'lib/string_to_number/to_number.rb', line 86 def to_number extract(@sentence, keys) end |