Module: Rocketeer::Helpers::Text
- Defined in:
- lib/rocketeer/helpers/text.rb
Instance Method Summary collapse
-
#pluralize(count, singular, plural = nil) ⇒ Object
Pluralizes the string.
-
#shorten_string(text, length = 30, truncate_string = "...") ⇒ Object
Shortens the string to the specified length.
Instance Method Details
#pluralize(count, singular, plural = nil) ⇒ Object
Pluralizes the string.
@example:
pluralize comments.count, 'comment'
35 36 37 |
# File 'lib/rocketeer/helpers/text.rb', line 35 def pluralize(count, singular, plural = nil) "#{count || 0} " + ((count == 1 || count =~ /^1(\.0+)?$/) ? singular : (plural || singular.pluralize)) end |
#shorten_string(text, length = 30, truncate_string = "...") ⇒ Object
Shortens the string to the specified length
@example:
shorten_string 'A very, very, long string', 5
51 52 53 54 55 |
# File 'lib/rocketeer/helpers/text.rb', line 51 def shorten_string(text, length = 30, truncate_string = "...") return if text.nil? l = length - truncate_string.length text.length > length ? text[/\A.{#{l}}\w*\;?/m][/.*[\w\;]/m] + truncate_string : text end |