Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/gamefic/core_ext/string.rb
Instance Method Summary collapse
-
#capitalize_first ⇒ String
(also: #cap_first)
Capitalize the first letter without changing the rest of the string.
-
#keywords ⇒ Array
Get an array of words split by any whitespace.
- #normalize ⇒ String
Instance Method Details
#capitalize_first ⇒ String 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.)
8 9 10 |
# File 'lib/gamefic/core_ext/string.rb', line 8 def capitalize_first "#{self[0, 1].upcase}#{self[1, length]}" end |
#keywords ⇒ Array
Get an array of words split by any whitespace.
16 17 18 |
# File 'lib/gamefic/core_ext/string.rb', line 16 def keywords gsub(/[\s-]+/, ' ').strip.downcase.split - %w[a an the] end |
#normalize ⇒ String
21 22 23 |
# File 'lib/gamefic/core_ext/string.rb', line 21 def normalize keywords.join(' ') end |