Module: Blur::TextHelper

Defined in:
lib/blur/text_helper.rb,
lib/blur/text_helper/version.rb

Constant Summary collapse

VERSION =
'0.1.0'.freeze

Instance Method Summary collapse

Instance Method Details

#pluralize(count, word) ⇒ Object

Returns the count and word where word is either singular or plural, depending on the count.

Examples:

pluralize(1, 'horse') # => "1 horse"
pluralize(2, 'cat') # => "2 cats"


15
16
17
# File 'lib/blur/text_helper.rb', line 15

def pluralize(count, word)
  "#{count} #{count == 1 ? word.singularize : word.pluralize}"
end

#sanitize(string) ⇒ Object

Sanitizes the string by removing carriage returns, newline feeds and redundant spaces.

Examples:

sanitize("the  quick brown  dog") # => "the quick brown dog"


24
25
26
# File 'lib/blur/text_helper.rb', line 24

def sanitize(string)
  string.gsub(/[\s]{2,}/, ' ').gsub(/[\r\n]/, ' ').strip
end