Class Lafcadio::English
In: lafcadio/util.rb
Parent: Object

A collection of English-language specific utility methods.

Methods

Public Class methods

Turns a camel-case string ("camel_case_to_english") to plain English ("camel case to english"). Each word is decapitalized.

Turns an English language string into camel case.

Given a singular noun, returns the plural form.

Returns the proper noun form of a string by capitalizing most of the words.

Examples:

  English.proper_noun("bosnia and herzegovina") ->
    "Bosnia and Herzegovina"
  English.proper_noun("macedonia, the former yugoslav republic of") ->
    "Macedonia, the Former Yugoslav Republic of"
  English.proper_noun("virgin islands, u.s.") ->
    "Virgin Islands, U.S."

Given a format for a template sentence, generates the sentence while accounting for details such as pluralization and whether to use "a" or "an".

format
The format string. Format codes are:
  • %num: Number
  • %is: Transitive verb. This will be turned into "is" or "are", depending on number.
  • %nam: Name. This will be rendered as either singular or plural, depending on number.
  • %a: Indefinite article. This will be turned into "a" or "an", depending on name.
name
The name of the object being described.
number
The number of the objects being describes.

Examples:

  English.sentence("There %is currently %num %nam", "product category",
                       0) -> "There are currently 0 product categories"
  English.sentence("There %is currently %num %nam", "product category",
                       1) -> "There is currently 1 product category"
  English.sentence("Add %a %nam", "invoice") -> "Add an invoice"

Does this word start with a vowel sound? "User" and "usury" don’t, but "ugly" does.

[Validate]