Class: Helpers
- Inherits:
-
Object
- Object
- Helpers
- Defined in:
- lib/helpers/helpers.rb
Class Method Summary collapse
-
.getLastCharacter(string) ⇒ String
Used to retrieve the last character of a string.
-
.removeLastCharacterIf(string, character) ⇒ String
Remove the last character of a string if the character is a given definition.
-
.removeMultipleLastCharacterIf(string, characters) ⇒ String
Remove the multiple last character of a string if the character is a given definition.
-
.replaceAllCharacter(string, pattern, replacement) ⇒ String
Replace all characters in a string given a pattern and a replacement string.
Class Method Details
.getLastCharacter(string) ⇒ String
Used to retrieve the last character of a string
7 8 9 10 |
# File 'lib/helpers/helpers.rb', line 7 def self.getLastCharacter(string) raise TypeError unless string.is_a? String return string[-1] end |
.removeLastCharacterIf(string, character) ⇒ String
Remove the last character of a string if the character is a given definition
17 18 19 20 21 22 |
# File 'lib/helpers/helpers.rb', line 17 def self.removeLastCharacterIf(string, character) raise TypeError unless character.is_a? String string = string.chomp(character) return string end |
.removeMultipleLastCharacterIf(string, characters) ⇒ String
Remove the multiple last character of a string if the character is a given definition
29 30 31 32 33 34 35 36 37 |
# File 'lib/helpers/helpers.rb', line 29 def self.removeMultipleLastCharacterIf(string, characters) raise TypeError unless characters.is_a? Array characters.each { |i| string = removeLastCharacterIf(string, i) } return string end |
.replaceAllCharacter(string, pattern, replacement) ⇒ String
Replace all characters in a string given a pattern and a replacement string
45 46 47 48 49 50 51 52 53 |
# File 'lib/helpers/helpers.rb', line 45 def self.replaceAllCharacter(string, pattern, replacement) raise TypeError unless string.is_a? String raise TypeError unless pattern.is_a? String raise TypeError unless replacement.is_a? String string = string.gsub(pattern, replacement) return string end |