module Stringer

Overview

Stringer (\ˈstriŋ-ər) - one that strings.

Useful utilities patched on top of the lovely String. Getting started is easy! Just add the Stringer shard as a dependency and then it's as simple as strumming along:

strum = "The quick brown fox jumps over the lazy dog"
strum.truncate(28) # => "The quick brown fox jumps..."

Defined in:

stringer.cr

Constant Summary

DEFAULT_TRUNCATE_OMISSION = "..."

Instance Method Summary

Instance Method Detail

def squish #

Trims leading/trailing whitespace and compacts internal whitespace

Examples:

strum = "  some \t\n messy\ttxt \n\t   "
strum.squish #=> "some messy txt"

Hat tip to Ruby on Rails inflections String#squish


[View source]
def truncate(length, options = {} of Symbol => String) #

Returns a string truncated at the specified length.

Options:

  • :omission => postfix applied to the truncated string (default "...")
  • :separator => separator to use for clean breaks (default nil)

Examples:

strum = "The quick brown fox jumps over the lazy dog"
strum.truncate(20) #=> "The quick brown f..."
strum.truncate(20, {:omission => "!!!"}) #=> "The quick brown f!!!"
strum.truncate(20, {:separator => " "}) #=> "The quick brown..."

Hat tip to Ruby on Rails inflections String#truncate


[View source]