Returns true if the string supplied is free from characters not allowed as an ATOM
# File lib/mail/utilities.rb, line 13 def atom_safe?( str ) not ATOM_UNSAFE === str end
Capitalizes a string that is joined by hyphens correctly.
Example:
string = 'resent-from-field' capitalize_field( string ) #=> 'Resent-From-Field'
# File lib/mail/utilities.rb, line 118 def capitalize_field( str ) str.to_s.split("-").map { |v| v.capitalize }.join("-") end
Takes an underscored word and turns it into a class name
Example:
constantize("hello") #=> "Hello" constantize("hello-there") #=> "HelloThere" constantize("hello-there-mate") #=> "HelloThereMate"
# File lib/mail/utilities.rb, line 129 def constantize( str ) str.to_s.split(/[-_]/).map { |v| v.capitalize }.to_s end
Swaps out all underscores (_) for hyphens (-) good for stringing from symbols a field name.
Example:
string = :resent_from_field dasherize ( string ) #=> 'resent_from_field'
# File lib/mail/utilities.rb, line 140 def dasherize( str ) str.to_s.downcase.gsub('_', '-') end
Wraps supplied string in double quotes unless it is already wrapped.
Additionally will escape any double quotation marks in the string with a single backslash in front of the ‘“’ character.
# File lib/mail/utilities.rb, line 54 def dquote( str ) str = $1 if str =~ /^"(.*)?"$/ # First remove all escaped double quotes: str = str.gsub(/\\"/, '"') # Then wrap and re-escape all double quotes '"' + str.gsub(/["]/) {|s| '\' + s } + '"' end
Escape parenthesies in a string
Example:
str = 'This is (a) string' escape_paren( str ) #=> 'This is \(a\) string'
# File lib/mail/utilities.rb, line 97 def escape_paren( str ) RubyVer.escape_paren( str ) end
Matches two objects with their to_s values case insensitively
Example:
obj2 = "This_is_An_object" obj1 = :this_IS_an_object match_to_s( obj1, obj2 ) #=> true
# File lib/mail/utilities.rb, line 108 def match_to_s( obj1, obj2 ) obj1.to_s.downcase == obj2.to_s.downcase end
Wraps a string in parenthesis and escapes any that are in the string itself.
Example:
string
# File lib/mail/utilities.rb, line 77 def paren( str ) RubyVer.paren( str ) end
If the string supplied has ATOM unsafe characters in it, will return the string quoted in double quotes, otherwise returns the string unmodified
# File lib/mail/utilities.rb, line 19 def quote_atom( str ) (ATOM_UNSAFE === str) ? dquote(str) : str end
If the string supplied has PHRASE unsafe characters in it, will return the string quoted in double quotes, otherwise returns the string unmodified
# File lib/mail/utilities.rb, line 25 def quote_phrase( str ) if RUBY_VERSION >= '1.9' original_encoding = str.encoding str.force_encoding('ASCII-8BIT') if (PHRASE_UNSAFE === str) dquote(str).force_encoding(original_encoding) else str.force_encoding(original_encoding) end else (PHRASE_UNSAFE === str) ? dquote(str) : str end end
If the string supplied has TOKEN unsafe characters in it, will return the string quoted in double quotes, otherwise returns the string unmodified
# File lib/mail/utilities.rb, line 46 def quote_token( str ) (TOKEN_UNSAFE === str) ? dquote(str) : str end
Returns true if the string supplied is free from characters not allowed as a TOKEN
# File lib/mail/utilities.rb, line 40 def token_safe?( str ) not TOKEN_UNSAFE === str end
Swaps out all underscores (_) for hyphens (-) good for stringing from symbols a field name.
Example:
string = :resent_from_field underscoreize ( string ) #=> 'resent_from_field'
# File lib/mail/utilities.rb, line 151 def underscoreize( str ) str.to_s.downcase.gsub('-', '_') end
Generated with the Darkfish Rdoc Generator 2.