Sha256: c8876adc2c22e96837f67a92d4cd16a30cacbef5566fabb7488872a32612d397

Contents?: true

Size: 589 Bytes

Versions: 8

Compression:

Stored size: 589 Bytes

Contents

# frozen_string_literal: true

class String
  # Capitalize the first letter without changing the rest of the string.
  # (String#capitalize makes the rest of the string lower-case.)
  #
  # @return [String] The capitalized text
  def capitalize_first
    "#{self[0, 1].upcase}#{self[1, length]}"
  end
  alias cap_first capitalize_first

  # Get an array of words split by any whitespace.
  #
  # @return [Array]
  def keywords
    gsub(/[\s-]+/, ' ').strip.downcase.split - %w[a an the]
  end

  # @return [String]
  def normalize
    keywords.join(' ')
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gamefic-3.6.0 lib/gamefic/core_ext/string.rb
gamefic-3.5.0 lib/gamefic/core_ext/string.rb
gamefic-3.4.0 lib/gamefic/core_ext/string.rb
gamefic-3.3.0 lib/gamefic/core_ext/string.rb
gamefic-3.2.1 lib/gamefic/core_ext/string.rb
gamefic-3.2.0 lib/gamefic/core_ext/string.rb
gamefic-3.1.0 lib/gamefic/core_ext/string.rb
gamefic-3.0.0 lib/gamefic/core_ext/string.rb