class Substitutions::Text
Constants
- SUBSTITUTIONS
Attributes
text[R]
Public Class Methods
new(text)
click to toggle source
# File lib/substitutions.rb, line 62 def initialize(text) @text = text end
Public Instance Methods
substitute()
click to toggle source
# File lib/substitutions.rb, line 66 def substitute # TODO swap minutes and years. Write test. substituted = @text substituted = years_and_minutes(substituted) SUBSTITUTIONS.each do |key,value| substituted = substituted.gsub(key, value) end substituted end
years_and_minutes(txt)
click to toggle source
# File lib/substitutions.rb, line 76 def years_and_minutes(txt) words = txt.split(" ") years_indexes = words.each_with_index.map{|w,i| i if w.match(/years/)}.compact minutes_indexes = words.each_with_index.map{|w,i| i if w.match(/minutes/)}.compact years_indexes.each{|i| words[i].gsub!(/years/, "minutes")} minutes_indexes.each{|i| words[i].gsub!(/minutes/, "years")} words.join(" ") end