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']
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.
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.