Module: Net::IMAP::StringFormatter

Defined in:
lib/net/imap/command_data.rb

Constant Summary collapse

LITERAL_REGEX =
/[\x80-\xff\r\n]/n

Class Method Summary collapse

Class Method Details

.nstring(str) ⇒ Object

coerces non-nil using to_s



300
301
302
# File 'lib/net/imap/command_data.rb', line 300

def nstring(str)
  str.nil? ? nil : string(str)
end

.string(str) ⇒ Object

coerces using to_s



290
291
292
293
294
295
296
297
# File 'lib/net/imap/command_data.rb', line 290

def string(str)
  str = str.to_s
  if str =~ LITERAL_REGEX
    Literal.new(str)
  else
    QuotedString.new(str)
  end
end

.valid_nstring?(str) ⇒ Boolean

Allows nil, symbols, and strings

Returns:

  • (Boolean)


285
286
287
# File 'lib/net/imap/command_data.rb', line 285

def valid_nstring?(str)
  str.nil? || valid_string?(str)
end

.valid_string?(str) ⇒ Boolean

Allows symbols in addition to strings

Returns:

  • (Boolean)


280
281
282
# File 'lib/net/imap/command_data.rb', line 280

def valid_string?(str)
  str.is_a?(Symbol) || str.respond_to?(:to_str)
end