Module: WolfCore::StringUtils
- Defined in:
- lib/wolf_core/utils/string_utils.rb
Instance Method Summary collapse
- #camelcase_to_spaces(str) ⇒ Object
- #clean_phone_number(phone) ⇒ Object
- #hash_str_to_json(hash_str) ⇒ Object
- #remove_blank_spaces(str) ⇒ Object
Instance Method Details
#camelcase_to_spaces(str) ⇒ Object
3 4 5 6 |
# File 'lib/wolf_core/utils/string_utils.rb', line 3 def camelcase_to_spaces(str) return if str.nil? str.gsub(/([A-Z])/, ' \1').strip.downcase.capitalize end |
#clean_phone_number(phone) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/wolf_core/utils/string_utils.rb', line 8 def clean_phone_number(phone) return if phone.nil? cleaned_phone = phone.to_s.gsub(/\D/, '') last_ten_digits = cleaned_phone[-10, 10] last_ten_digits end |
#hash_str_to_json(hash_str) ⇒ Object
19 20 21 |
# File 'lib/wolf_core/utils/string_utils.rb', line 19 def hash_str_to_json(hash_str) hash_str.gsub('=>', ':').gsub('\"', '"').gsub('{', '{').gsub('}', '}').gsub(/(\w+)(?=\s*:)/) { |key| "\"#{key}\"" } end |
#remove_blank_spaces(str) ⇒ Object
15 16 17 |
# File 'lib/wolf_core/utils/string_utils.rb', line 15 def remove_blank_spaces(str) str&.gsub(/\s+/, '') end |