123456789_123456789_123456789_123456789_123456789_

Module: Net::IMAP::StringFormatter

Do not use. This module is for internal use only.
Relationships & Source Files
Defined in: lib/net/imap/command_data.rb

Constant Summary

Class Method Summary

Class Method Details

.literal_or_literal8(input, name: "argument") (mod_func)

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 374

def literal_or_literal8(input, name: "argument")
  return input if input in Literal | Literal8
  data = String.try_convert(input) \
    or raise TypeError, "expected #{name} to be String, got #{input.class}"
  type = data.include?("\0") ? Literal8 : Literal
  type.new(data:)
end

.nstring(str) (mod_func)

coerces non-nil using to_s

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 403

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

.string(str) (mod_func)

coerces using to_s

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 393

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

.valid_nstring?(str) ⇒ Boolean (mod_func)

Allows nil, symbols, and strings

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 388

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

.valid_string?(str) ⇒ Boolean (mod_func)

Allows symbols in addition to strings

[ GitHub ]

  
# File 'lib/net/imap/command_data.rb', line 383

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