Module: Net::IMAP::NumValidator

Defined in:
lib/net/imap.rb

Overview

Common validators of number and nz_number types

Class Method Summary collapse

Class Method Details

.ensure_mod_sequence_value(num) ⇒ Object

Ensure argument is ‘mod_sequence_value’ or raise DataFormatError

Raises:



1703
1704
1705
1706
1707
1708
# File 'lib/net/imap.rb', line 1703

def ensure_mod_sequence_value(num)
  return if valid_mod_sequence_value?(num)

  msg = "mod_sequence_value must be unsigned 64-bit integer: #{num}"
  raise DataFormatError, msg
end

.ensure_number(num) ⇒ Object

Ensure argument is ‘number’ or raise DataFormatError

Raises:



1687
1688
1689
1690
1691
1692
# File 'lib/net/imap.rb', line 1687

def ensure_number(num)
  return if valid_number?(num)

  msg = "number must be unsigned 32-bit integer: #{num}"
  raise DataFormatError, msg
end

.ensure_nz_number(num) ⇒ Object

Ensure argument is ‘nz_number’ or raise DataFormatError

Raises:



1695
1696
1697
1698
1699
1700
# File 'lib/net/imap.rb', line 1695

def ensure_nz_number(num)
  return if valid_nz_number?(num)

  msg = "nz_number must be non-zero unsigned 32-bit integer: #{num}"
  raise DataFormatError, msg
end

.valid_mod_sequence_value?(num) ⇒ Boolean

Check is passed argument valid ‘mod_sequence_value’ in RFC 4551 terminology

Returns:

  • (Boolean)


1678
1679
1680
1681
1682
1683
1684
# File 'lib/net/imap.rb', line 1678

def valid_mod_sequence_value?(num)
  # mod-sequence-value  = 1*DIGIT
  #                        ; Positive unsigned 64-bit integer
  #                        ; (mod-sequence)
  #                        ; (1 <= n < 18,446,744,073,709,551,615)
  num >= 1 && num < 18446744073709551615
end

.valid_number?(num) ⇒ Boolean

Check is passed argument valid ‘number’ in RFC 3501 terminology

Returns:

  • (Boolean)


1660
1661
1662
1663
1664
1665
1666
# File 'lib/net/imap.rb', line 1660

def valid_number?(num)
  # [RFC 3501]
  # number          = 1*DIGIT
  #                    ; Unsigned 32-bit integer
  #                    ; (0 <= n < 4,294,967,296)
  num >= 0 && num < 4294967296
end

.valid_nz_number?(num) ⇒ Boolean

Check is passed argument valid ‘nz_number’ in RFC 3501 terminology

Returns:

  • (Boolean)


1669
1670
1671
1672
1673
1674
1675
# File 'lib/net/imap.rb', line 1669

def valid_nz_number?(num)
  # [RFC 3501]
  # nz-number       = digit-nz *DIGIT
  #                    ; Non-zero unsigned 32-bit integer
  #                    ; (0 < n < 4,294,967,296)
  num != 0 && valid_number?(num)
end