Sha256: fd8bda39f889457a96a277ab9a64cab4d59cb4512bc636cc02e9d6657ba0df57

Contents?: true

Size: 659 Bytes

Versions: 7

Compression:

Stored size: 659 Bytes

Contents

# frozen_string_literal: true

# A collection of utilities for strings.
module StringUtils

  # Converts the given query String to a Hash object.
  # A query string is identified by a set of
  # key-value pairs in the format "{key}={value}"
  # separated by the '&' character.
  #
  # Arguments:
  #   string: the string to convert
  def self.query_string_to_hash(string)
    dict = {}
    string.split('&').map do |pair|
      key, value = pair.split('=')
      dict[key] = value.sub('+', ' ')
    end
    dict
  end

end

class String

  # Capitalizes every word of the given String.
  def titleize
    self.split('-').map(&:capitalize).join('-')
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
gyoza-languages-1.0.5 lib/gyoza-languages/string_utils.rb
gyoza-languages-1.0.4 lib/gyoza-languages/string_utils.rb
gyoza-languages-1.0.3 lib/gyoza-languages/string_utils.rb
gyoza-languages-1.0.2 lib/gyoza-languages/string_utils.rb
gyoza-languages-1.0.1 lib/gyoza-languages/string_utils.rb
gyoza-languages-1.0.0 lib/gyoza-languages/string_utils.rb
gyoza-languages-0.1.0 lib/gyoza-languages/string_utils.rb