Skip to content

Instantly share code, notes, and snippets.

@Arkham
Created February 5, 2013 00:04
Show Gist options
  • Save Arkham/4710943 to your computer and use it in GitHub Desktop.
Save Arkham/4710943 to your computer and use it in GitHub Desktop.
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