Created
February 5, 2013 00:04
-
-
Save Arkham/4710943 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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