Class: String

Class | String
In: | lib/extlib/blank.rb lib/extlib/inflection.rb lib/extlib/string.rb
Parent: | Object

### Methods

/ blank? camel_case compress_lines escape_regexp margin plural pluralize relative_path_from singular singularize snake_case t to_const_path to_const_string translate translations unescape_regexp

### Public Class methods

translate(value)

Overwrite this method to provide your own translations.

translations()

### Public Instance methods

/(o)

Join with o as a file path.

      "merb"/"core_ext" #=> "merb/core_ext"

@param [String] o Path component to join with receiver.

@return [String] Receiver joined with o as a file path.

@api public

blank?()

Strips out whitespace then tests if the string is empty.

      "".blank?         #=>  true
      "     ".blank?    #=>  true
      " hey ho ".blank? #=>  false

@return [TrueClass, FalseClass]

@api public

camel_case()

Convert to camel case.

      "foo_bar".camel_case          #=> "FooBar"

@return [String] Receiver converted to camel case.

@api public

compress_lines(spaced = true)

Replace sequences of whitespace (including newlines) with either a single space or remove them entirely (according to param spaced)

      <<QUERY.compress_lines
        SELECT name
        FROM users
      QUERY => "SELECT name FROM users"

@param [TrueClass, FalseClass] spaced (default=true)

      Determines whether returned string has whitespace collapsed or removed

@return [String] Receiver with whitespace (including newlines) replaced

@api public

escape_regexp()

Escape all regexp special characters.

      "*?{}.".escape_regexp   #=> "\\*\\?\\{\\}\\."

@return [String] Receiver with all regexp special characters escaped.

@api public

margin(indicator = nil)

Remove whitespace margin.

@param [Object] indicator ???

@return [String] receiver with whitespace margin removed

@api public

plural()
pluralize()

Alias for plural

relative_path_from(other)

Calculate a relative path from other.

      "/opt/local/lib".relative_path_from("/opt/local/lib/ruby/site_ruby") # => "../.."

@param [String] other Base path to calculate from.

@return [String] Relative path from other to receiver.

@api public

singular()
singularize()

Alias for singular

snake_case()

Convert to snake case.

      "FooBar".snake_case           #=> "foo_bar"
      "HeadlineCNNNews".snake_case  #=> "headline_cnn_news"
      "CNN".snake_case              #=> "cnn"

@return [String] Receiver converted to snake case.

@api public

t(*values)

Formats String for easy translation. Replaces an arbitrary number of values using numeric identifier replacement.

      "%s %s %s" % %w(one two three)        #=> "one two three"
      "%3$s %2$s %1$s" % %w(one two three)  #=> "three two one"

@param [to_s] values

      A list of values to translate and interpolate into receiver

@return [String]

      Receiver translated with values translated and interpolated positionally

@api public

to_const_path()

Convert a constant name to a path, assuming a conventional structure.

      "FooBar::Baz".to_const_path # => "foo_bar/baz"

@return [String] Path to the file containing the constant named by receiver

      (constantized string), assuming a conventional structure.

@api public

to_const_string()

Convert a path string to a constant name.

      "merb/core_ext/string".to_const_string #=> "Merb::CoreExt::String"

@return [String] Receiver converted to a constant name.

@api public

unescape_regexp()

Unescape all regexp special characters.

      "\\*\\?\\{\\}\\.".unescape_regexp #=> "*?{}."

@return [String] Receiver with all regexp special characters unescaped.

@api public

[Validate]