public
Created

  • Download Gist
refactor.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
class AcronymSolver
attr_reader :text
 
def initialize(text)
@text = text
end
 
def self.substitutions
{
:PPC => 'Pocket PC',
:DVD => 'Digital Versatile Disc'
}
end
 
def solve!
AcronymSolver.substitutions.each do |acronym, solution|
text.gsub!(/ #{acronym} /, %[ <acronym title="#{solution}">#{acronym}</acronym> ])
end
text
end
end
 
def acronym_page
@page = Page.find(params[:id])
@page.description = AcronymSolver.new(@page.description).solve!
if @page.save
flash[:notice] = 'Acronimi sostituiti.'
redirect_to :action => 'modpag', :id => @page
end
end
 
def acronym_image
@picture = Picture.find(params[:id])
@picture.text = AcronymSolver.new(@picture.text).solve!
if @picture.save
flash[:notice] = 'Acronimi sostituiti.'
redirect_to :action => 'modpict', :id => @picture.guide.id
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.