Created
February 3, 2011 16:13
-
-
Save rentalcustard/809694 to your computer and use it in GitHub Desktop.
Genius legacy code
This file contains hidden or 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 String | |
def replace_line_break | |
return String.new if self.nil? | |
return_str = String.new | |
return_str = self.gsub(/[\x0D|\x0A]/,'<br />') | |
return return_str | |
end | |
end |
This file contains hidden or 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
module SalaryFormatting | |
def self.included(base) | |
base.module_eval do | |
extend ClassMethods | |
end | |
end | |
def formatted_salary | |
salary && self.class.pad_salary(self.salary) | |
end | |
module ClassMethods | |
def pad_salary(salary) | |
stripped = attr.to_s.gsub(/\D/, "") | |
( "%8d" % stripped ).gsub(' ', '0') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment