This gem extends text manipulation to classes like String, Boolean etc..
Install the gem and add to the application's Gemfile by executing:
$ bundle add render-text-helper
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install render-text-helper
This function makes sure that the string does not go over a specific given limit. It has three parameters. "limit" which is defaulted to 32 and controls how far to show the characters. "more_indicator" which defaults to "." and controls which character to use to indicate there are more. "indicator_length" which defaults to 3 and controls how many times to show the more indicator.
'hello'.limit_print
'hello'
'elephant'.limit_print(limit: 2)
'el...'
'elephant'.limit_print(limit: 2, indicator_length: 0)
'el'
'elephant'.limit_print(limit: 3, more_indicator: '_')
'ele___'
'elephant'.limit_print(limit: 4, more_indicator: '*', indicator_length: 2)
'elep**'Take a string and splits it to an array by ",", "|", space, or by a passed parameter. It also strips whitespace.
'cat, dog, matt'.to_smart_array
['cat', 'dog', 'matt']
' cat , dog, matt,pat '.to_smart_array
['cat', 'dog', 'matt', 'pat']
' cat dog matt pat '.to_smart_array
['cat', 'dog', 'matt', 'pat']
' cat # dog# matt#pat '.to_smart_array('#')
['cat', 'dog', 'matt', 'pat']Titleize for none rails project. It also removes unnecessary white spaces and converts "_" to spaces.
'hello world!'.to_titleize
"Hello World!"
'HELLO WORLD!'.to_titleize
"Hello World!"
'hello_world!'.to_titleize
"Hello World!"
' hello world! '.to_titleize
"Hello World!"Strips all characters instead of letters, numbers and space.
It also trims spaces at the beginning and the end.
You have the option to disallow spaces as well.
This is good for common input like name, address, other standard writings.
' A1!2@3#4$ 5%6^S7&8*9 F(0)-_=+Z|/?.>rlq<,*/ '.to_letters_and_numbers
"A1234 56S789 F0Zrlq"
' A1!2@3#4$ 5%6^S7&8*9 F(0)-_=+Z|/?.>rlq<,*/ '.to_letters_and_numbers(allow_space: false)
"A123456S789F0Zrlq"This function returns a string from a boolean to yes or no. It takes in optional casting parameter which can be either capitalize, upcase, or downcase.
true.to_yes_no
'Yes'
true.to_yes_no(:upcase)
'YES'
false.to_yes_no(:downcase)
'no'
false.to_yes_no
false.to_yes_no(:capitalize)
'No'This function returns a string from a boolean to Y or N
true.to_yn
'Y'
true.to_yn(capital_letter: false)
'y'
false.to_yn
'N'
false.to_yn(capital_letter: false)
'n'Returns 1 for true and 0 for false on a boolean object.
It takes float and adds percentage to it.
25.75.add_percent_sign
'25.75%'Bug reports and pull requests are welcome on GitHub at https://github.com/SaimonL/render-text-helper
The gem is available as open source under the terms of the MIT License.