Module: ActiveStripper::Helpers
- Defined in:
- lib/active_stripper/helpers.rb
Class Method Summary collapse
-
.cast_to_float(val) ⇒ Float
Convert value to Float value if format match.
-
.cast_to_int(val) ⇒ Integer
Convert value to Integer value if format match.
-
.empty_string_to_nil(val) ⇒ String/Nil
Set value to nil if val is an empty string.
-
.end_space_stripper(val) ⇒ String
Remove all trailing spaces at the end of the string.
-
.multiple_space_stripper(val) ⇒ String
Replace double spaces with single space.
-
.start_space_stripper(val) ⇒ String
Remove all trailong spaces at the beginning of the string.
-
.to_lower_stripper(val) ⇒ String
Lower case the entire string through String#downcase.
-
.white_space_stripper(val) ⇒ String
Apply String#strip to value.
Class Method Details
.cast_to_float(val) ⇒ Float
Convert value to Float value if format match. nil and empty string returns 0.0 other value are converted with Float(val) command if value is not convertible raise an argument Error Only to use if val is NOT a BigDecimal or should results in one
106 107 108 109 |
# File 'lib/active_stripper/helpers.rb', line 106 def cast_to_float(val) return 0.0 if !val || val == "" return Float( (val.is_a?(String)) ? val.tr(",", ".") : val ) end |
.cast_to_int(val) ⇒ Integer
Convert value to Integer value if format match. nil and empty string returns 0 other value are converted with Integer(val) command if value is not convertible raise an argument Error Only to use if val is NOT a BigDecimal or should results in one
91 92 93 94 |
# File 'lib/active_stripper/helpers.rb', line 91 def cast_to_int(val) return 0 if !val || val == "" return Integer(val) end |
.empty_string_to_nil(val) ⇒ String/Nil
Set value to nil if val is an empty string
76 77 78 79 |
# File 'lib/active_stripper/helpers.rb', line 76 def empty_string_to_nil(val) return if !val || val == "" return val end |
.end_space_stripper(val) ⇒ String
Remove all trailing spaces at the end of the string
40 41 42 43 |
# File 'lib/active_stripper/helpers.rb', line 40 def end_space_stripper(val) return if !val return val.gsub(/\s+$/, "") end |
.multiple_space_stripper(val) ⇒ String
Replace double spaces with single space
28 29 30 31 |
# File 'lib/active_stripper/helpers.rb', line 28 def multiple_space_stripper(val) return if !val return val.gsub(/\s+/, " ") end |
.start_space_stripper(val) ⇒ String
Remove all trailong spaces at the beginning of the string
52 53 54 55 |
# File 'lib/active_stripper/helpers.rb', line 52 def start_space_stripper(val) return if !val return val.gsub(/^\s+/, "") end |
.to_lower_stripper(val) ⇒ String
Lower case the entire string through String#downcase
64 65 66 67 |
# File 'lib/active_stripper/helpers.rb', line 64 def to_lower_stripper(val) return if !val return val.downcase end |
.white_space_stripper(val) ⇒ String
Apply String#strip to value
16 17 18 19 |
# File 'lib/active_stripper/helpers.rb', line 16 def white_space_stripper(val) return if !val return val.strip end |