Returns true if the string supplied is free from characters not allowed as an ATOM
# File lib/mail/utilities.rb, line 7 7: def atom_safe?( str ) 8: not ATOM_UNSAFE === str 9: end
Wraps a string in angle brackets and escapes any that are in the string itself
Example:
bracket( 'This is a string' ) #=> '<This is a string>'
# File lib/mail/utilities.rb, line 93
93: def bracket( str )
94: RubyVer.bracket( str )
95: 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 143
143: def capitalize_field( str )
144: str.to_s.split("-").map { |v| v.capitalize }.join("-")
145: 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 154
154: def constantize( str )
155: str.to_s.split(/[-_]/).map { |v| v.capitalize }.to_s
156: 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 165
165: def dasherize( str )
166: str.to_s.gsub('_', '-')
167: 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 48
48: def dquote( str )
49: match = str.match(/^"(.*)?"$/)
50: str = match[1] if match
51: # First remove all escaped double quotes:
52: str = str.gsub(/\\"/, '"')
53: # Then wrap and re-escape all double quotes
54: '"' + str.gsub(/["]/) {|s| '\' + s } + '"'
55: 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 114
114: def escape_paren( str )
115: RubyVer.escape_paren( str )
116: end
# File lib/mail/utilities.rb, line 182
182: def map_lines( str, &block )
183: results = []
184: str.each_line do |line|
185: results << yield(line)
186: end
187: results
188: end
# File lib/mail/utilities.rb, line 200
200: def map_lines( str, &block )
201: str.each_line.map(&block)
202: end
# File lib/mail/utilities.rb, line 204
204: def map_with_index( enum, &block )
205: enum.each_with_index.map(&block)
206: end
# File lib/mail/utilities.rb, line 190
190: def map_with_index( enum, &block )
191: results = []
192: enum.each_with_index do |token, i|
193: results[i] = yield(token, i)
194: end
195: results
196: 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 133
133: def match_to_s( obj1, obj2 )
134: obj1.to_s.downcase == obj2.to_s.downcase
135: end
Wraps a string in parenthesis and escapes any that are in the string itself.
Example:
paren( 'This is a string' ) #=> '(This is a string)'
# File lib/mail/utilities.rb, line 73
73: def paren( str )
74: RubyVer.paren( str )
75: 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 13
13: def quote_atom( str )
14: atom_safe?( str ) ? str : dquote(str)
15: 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 19
19: def quote_phrase( str )
20: if RUBY_VERSION >= '1.9'
21: original_encoding = str.encoding
22: str.force_encoding('ASCII-8BIT')
23: if (PHRASE_UNSAFE === str)
24: dquote(str).force_encoding(original_encoding)
25: else
26: str.force_encoding(original_encoding)
27: end
28: else
29: (PHRASE_UNSAFE === str) ? dquote(str) : str
30: end
31: 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 40
40: def quote_token( str )
41: token_safe?( str ) ? str : dquote(str)
42: end
Returns true if the string supplied is free from characters not allowed as a TOKEN
# File lib/mail/utilities.rb, line 34
34: def token_safe?( str )
35: not TOKEN_UNSAFE === str
36: end
Unwraps a string from being wrapped in parenthesis
Example:
str = '<This is a string>' unbracket( str ) #=> 'This is a string'
# File lib/mail/utilities.rb, line 103
103: def unbracket( str )
104: match = str.match(/^\<(.*?)\>$/)
105: match ? match[1] : str
106: end
Swaps out all hyphens (-) for underscores (_) good for stringing to symbols a field name.
Example:
string = :resent_from_field underscoreize ( string ) #=> 'resent_from_field'
# File lib/mail/utilities.rb, line 176
176: def underscoreize( str )
177: str.to_s.downcase.gsub('-', '_')
178: end
Unwraps a string from being wrapped in parenthesis
Example:
str = '(This is a string)' unparen( str ) #=> 'This is a string'
# File lib/mail/utilities.rb, line 83
83: def unparen( str )
84: match = str.match(/^\((.*?)\)$/)
85: match ? match[1] : str
86: end
Unwraps supplied string from inside double quotes.
Example:
string = '"This is a string"' unquote(string) #=> 'This is a string'
# File lib/mail/utilities.rb, line 63
63: def unquote( str )
64: match = str.match(/^"(.*?)"$/)
65: match ? match[1] : str
66: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.