Class: Numerouno::Substitution

Inherits:
Object
  • Object
show all
Includes:
Numbers
Defined in:
lib/numerouno/substitution.rb

Constant Summary

Constants included from Numbers

Numbers::NUMBER_LOOKUP, Numbers::NUMBER_STRINGS

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Substitution

Returns a new instance of Substitution.



9
10
11
# File 'lib/numerouno/substitution.rb', line 9

def initialize source
  @source = source
end

Instance Method Details

#subObject



13
14
15
16
17
18
19
20
21
# File 'lib/numerouno/substitution.rb', line 13

def sub
  matches = {}
  
  NUMBER_STRINGS.each do |number_string, number|
    matches = matches_within(@source, number_string).merge(matches)
  end

  matches.empty? ? @source : replace(matches, @source)
end