Class: String
- Inherits:
-
Object
- Object
- String
- Extended by:
- FatCore::String::ClassMethods
- Includes:
- FatCore::String
- Defined in:
- lib/fat_core/string.rb
Generating collapse
-
.random(size = 8) ⇒ Object
extended
from FatCore::String::ClassMethods
Return a random string composed of all lower-case letters of length
size
.
Transforming collapse
-
#as_date ⇒ Date
included
from FatCore::String
Convert a string representing a date with only digits, hyphens, or slashes to a Date.
-
#as_string ⇒ String
included
from FatCore::String
Return self unmodified.
-
#as_sym ⇒ Symbol
included
from FatCore::String
Convert to a lower-case symbol with all white space converted to a single '_' and all non-alphanumerics deleted, such that the string will work as an unquoted Symbol.
-
#clean ⇒ String
included
from FatCore::String
Remove leading and trailing white space and compress internal runs of white space to a single space.
-
#entitle ⇒ String
included
from FatCore::String
Return self capitalized according to the conventions for capitalizing titles of books or articles.
-
#tex_quote ⇒ String
included
from FatCore::String
Return self with special TeX characters replaced with control-sequences that output the literal value of the special characters instead.
-
#wrap(width = 70, hang = 0) ⇒ String
included
from FatCore::String
Return a string wrapped to
width
characters with lines following the first indented byhang
characters.
Numbers collapse
-
#commas(places = nil) ⇒ String
included
from FatCore::String
If the string is a valid number, return a string that adds grouping commas to the whole number part; otherwise, return self.
-
#number? ⇒ Boolean
included
from FatCore::String
Return whether self is convertible into a valid number.
Matching collapse
-
#distance(other) ⇒ Integer
included
from FatCore::String
Return the Damerau-Levenshtein distance between self an another string using a transposition block size of 1 and quitting if a max distance of 10 is reached.
-
#fuzzy_match(matcher) ⇒ String?
included
from FatCore::String
Return the matched portion of self, minus punctuation characters, if self matches the string
matcher
using the following notion of matching:. -
#matches_with(matcher) ⇒ nil, String
included
from FatCore::String
Test whether self matches the
matcher
treatingmatcher
as a case-insensitive regular expression if it is of the form '/.../' or as a string to #fuzzy_match against otherwise. -
#to_regexp ⇒ Regexp
included
from FatCore::String
Convert a string of the form '/.../Iixm' to a regular expression.
Class Method Details
.random(size = 8) ⇒ Object Originally defined in module FatCore::String::ClassMethods
Return a random string composed of all lower-case letters of length
size
Instance Method Details
#as_date ⇒ Date Originally defined in module FatCore::String
Convert a string representing a date with only digits, hyphens, or slashes to a Date.
#as_string ⇒ String Originally defined in module FatCore::String
Return self unmodified. This method is here so to comply with the API of Symbol#as_string so that it can be applied to a variable that is either a String or a Symbol.
#as_sym ⇒ Symbol Originally defined in module FatCore::String
Convert to a lower-case symbol with all white space converted to a single '_' and all non-alphanumerics deleted, such that the string will work as an unquoted Symbol.
#clean ⇒ String Originally defined in module FatCore::String
Remove leading and trailing white space and compress internal runs of white space to a single space.
#commas(places = nil) ⇒ String Originally defined in module FatCore::String
If the string is a valid number, return a string that adds grouping commas to the whole number part; otherwise, return self. Round the number to the given number places after the decimal if places is positive; round to the left of the decimal if places is negative. Pad with zeroes on the right for positive places, on the left for negative places.
#distance(other) ⇒ Integer Originally defined in module FatCore::String
Return the Damerau-Levenshtein distance between self an another string using a transposition block size of 1 and quitting if a max distance of 10 is reached.
#entitle ⇒ String Originally defined in module FatCore::String
Return self capitalized according to the conventions for capitalizing titles of books or articles. Tries to follow the rules of the University of Chicago's A Manual of Style, Section 7.123, except to the extent that doing so requires knowing the parts of speech of words in the title. Also tries to use sensible capitalization for things such as postal address abbreviations, like P.O Box, Ave., Cir., etc. Considers all-consonant words of 3 or more characters as acronyms to be kept all uppercase, e.g., ddt => DDT, and words that are all uppercase in the input are kept that way, e.g. IBM stays IBM. Thus, if the source string is all uppercase, you should lowercase the whole string before using #entitle, otherwise is will not have the intended effect.
#fuzzy_match(matcher) ⇒ String? Originally defined in module FatCore::String
Return the matched portion of self, minus punctuation characters, if self
matches the string matcher
using the following notion of matching:
- Remove all periods, commas, apostrophes, and asterisks (the punctuation
characters) from both self and
matcher
, - Treat ':' in the matcher as the equivalent of '.*' in a regular expression, that is, match anything in self,
- Ignore case in the match
- Match if any part of self matches
matcher
#matches_with(matcher) ⇒ nil, String Originally defined in module FatCore::String
Test whether self matches the matcher
treating matcher
as a
case-insensitive regular expression if it is of the form '/.../' or as a
string to #fuzzy_match against otherwise.
#number? ⇒ Boolean Originally defined in module FatCore::String
Return whether self is convertible into a valid number.
#tex_quote ⇒ String Originally defined in module FatCore::String
Return self with special TeX characters replaced with control-sequences that output the literal value of the special characters instead. It handles _, $, &, %, #, {, }, \, ^, ~, <, and >.
#to_regexp ⇒ Regexp Originally defined in module FatCore::String
Convert a string of the form '/.../Iixm' to a regular expression. However, make the regular expression case-insensitive by default and extend the modifier syntax to allow '/I' to indicate case-sensitive. Without the surrounding '/', do not make the Regexp case insensitive, just translate it to a Regexp with Regexp.new.
#wrap(width = 70, hang = 0) ⇒ String Originally defined in module FatCore::String
Return a string wrapped to width
characters with lines following the
first indented by hang
characters.