Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/gamefic/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#capitalize_firstString Also known as: cap_first

Capitalize the first letter without changing the rest of the string. (String#capitalize makes the rest of the string lower-case.)

Returns:

  • (String)

    The capitalized text



8
9
10
# File 'lib/gamefic/core_ext/string.rb', line 8

def capitalize_first
  "#{self[0, 1].upcase}#{self[1, length]}"
end

#keywordsArray

Get an array of words split by any whitespace.

Returns:



16
17
18
# File 'lib/gamefic/core_ext/string.rb', line 16

def keywords
  gsub(/[\s-]+/, ' ').strip.downcase.split - %w[a an the]
end

#normalizeString

Returns:



21
22
23
# File 'lib/gamefic/core_ext/string.rb', line 21

def normalize
  keywords.join(' ')
end