Skip to content

@Arkham /refactor.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.