Module: Cape::Util Private

Defined in:
lib/cape/util.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Provides utility functions.

Class Method Summary collapse

Class Method Details

.pluralize(singular_noun, count = 2) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Conditionally transforms the specified noun into its plural form.

Parameters:

  • singular_noun (String)

    a singular noun

  • count (Fixnum) (defaults to: 2)

    the quantity of singular_noun

Returns:

  • (String)

    the plural of singular_noun, unless count is 1



14
15
16
17
18
# File 'lib/cape/util.rb', line 14

def self.pluralize(singular_noun, count=2)
  return singular_noun if count == 1

  "#{singular_noun}s"
end

.to_list_phrase(array) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Builds a list phrase from the elements of the specified array.

Parameters:

  • array (Array of String)

    zero or more nouns

Returns:

  • (String)

    the elements of array, joined with commas and “and”, as appropriate



26
27
28
29
30
# File 'lib/cape/util.rb', line 26

def self.to_list_phrase(array)
  return array.join(' and ') if (array.length <= 2)

  [array[0...-1].join(', '), array[-1]].join ', and '
end