Closed DolezalDavid closed 3 years ago
I found solution with more constants, but it's not exactly what I prefere. So solution via array will be better, probably faster.
Here is my half-solution:
charact1 ="*!"
charact2 ="!*"
charact3 ="_!"
charact4 ="!_"
charact5 ="+!"
charact6 ="!+"
charact7 ="-!"
charact8 ="!-"
if description_changed?
if self.description
self.description = [self.description,""].join
self.description = self.description.gsub charact1, '!'
self.description = self.description.gsub charact2, '!'
self.description = self.description.gsub charact3, '!'
self.description = self.description.gsub charact4, '!'
self.description = self.description.gsub charact5, '!'
self.description = self.description.gsub charact6, '!'
self.description = self.description.gsub charact7, '!'
self.description = self.description.gsub charact8, '!'
end
end
if self.notes
self.notes = [self.notes,""].join
self.notes = self.notes.gsub charact1, '!'
self.notes = self.notes.gsub charact2, '!'
self.notes = self.notes.gsub charact3, '!'
self.notes = self.notes.gsub charact4, '!'
self.notes = self.notes.gsub charact5, '!'
self.notes = self.notes.gsub charact6, '!'
self.notes = self.notes.gsub charact7, '!'
self.notes = self.notes.gsub charact8, '!'
end
Any idea for reduction of constants in to one? :-) @airtibu?
I would use a regexp:
self.description.gsub!(/[*_+-]?![*_+-]?/, '!')
Hi Karel, thank for your support. it works good. I close this post with your solution. :-)
Hi everybody, I need to replace before save some characters in description and notes.
When you found something from this:
*! or !* or _! or !_ or +! or !+ or -! or !-
replace it whit this:!
I tried to use:
but I don't know how to write characters into const charact. Any idea?
Thx for your help.
David