Class: String
Instance Method Summary collapse
-
#escape_sql ⇒ Object
replaces ‘ with ” and \ (two backslashes) with \\ (two escaped backslashes).
- #is_valid_dollar_amount? ⇒ Boolean
- #scrubbed_dollar_amount ⇒ Object
- #scrubbed_dollar_amount_if_valid ⇒ Object
Instance Method Details
#escape_sql ⇒ Object
replaces ‘ with ” and \ (two backslashes) with \\ (two escaped backslashes)
62 63 64 |
# File 'lib/gci-class-extensions.rb', line 62 def escape_sql self.gsub(/\\/, '\&\&').gsub(/'/, "''") end |
#is_valid_dollar_amount? ⇒ Boolean
47 48 49 50 |
# File 'lib/gci-class-extensions.rb', line 47 def is_valid_dollar_amount? # Optional parentheses or negative sign before or after the optional dollar sign, any number of digits and commas, followed by optional . and 1 or 2 digits, and optional close parentheses, with nothing on either side strip =~ /^[\(-]?\$?[\(-]?[\d,]+(\.\d{1,2})?\)?$/ ? true : false end |
#scrubbed_dollar_amount ⇒ Object
52 53 54 55 |
# File 'lib/gci-class-extensions.rb', line 52 def scrubbed_dollar_amount # first strip out dollar signs and commas, then convert "(12.34)" to "-12.34" strip.gsub(/[\$,]/,"").gsub(/^\((.*)\)$/, '-\1') end |
#scrubbed_dollar_amount_if_valid ⇒ Object
57 58 59 |
# File 'lib/gci-class-extensions.rb', line 57 def scrubbed_dollar_amount_if_valid is_valid_dollar_amount? ? scrubbed_dollar_amount : self end |