Module | N::StringUtils |
In: |
lib/glue/string.rb
|
General string utilities collection.
Implement as a module to avoid class polution. You can still Ruby‘s advanced features to include the module in your class. Passing the object to act upon allows to check for nil, which isn‘t possible if you use self.
MATCH | = | 0 |
Apply a set of rules (regular expression matches) to the string
Requirements:
Input:the string to rewrite the array containing rule-pairs (match, rewrite) Output:the rewritten string |
|
REWRITE | = | 1 |
returns short abstract of long strings (first ‘count’ characters, chopped at the nearest word, appended by ’…’) force_cutoff: break forcibly at ‘count’ chars. Does not accept count < 2.
Enforces a maximum width of a string inside an html container. If the string exceeds this maximum width the string gets wraped.
Not really useful, better use the CSS overflow: hidden functionality.
the string to be wrapped the enforced width the separator used for wrapping
the wrapped string
text = "1111111111111111111111111111111111111111111" text = wrap(text, 10, " ") p text # => "1111111111 1111111111 1111111111"
See the test cases to better understand the behaviour!