Module: Net::IMAP::NumValidator
- Defined in:
- lib/net/imap/data_encoding.rb
Overview
Common validators of number and nz_number types
Class Method Summary collapse
-
.ensure_mod_sequence_value(num) ⇒ Object
Ensure argument is ‘mod_sequence_value’ or raise DataFormatError.
-
.ensure_number(num) ⇒ Object
Ensure argument is ‘number’ or raise DataFormatError.
-
.ensure_nz_number(num) ⇒ Object
Ensure argument is ‘nz_number’ or raise DataFormatError.
-
.valid_mod_sequence_value?(num) ⇒ Boolean
Check is passed argument valid ‘mod_sequence_value’ in RFC 4551 terminology.
-
.valid_number?(num) ⇒ Boolean
Check is passed argument valid ‘number’ in RFC 3501 terminology.
-
.valid_nz_number?(num) ⇒ Boolean
Check is passed argument valid ‘nz_number’ in RFC 3501 terminology.
Class Method Details
.ensure_mod_sequence_value(num) ⇒ Object
Ensure argument is ‘mod_sequence_value’ or raise DataFormatError
204 205 206 207 208 209 |
# File 'lib/net/imap/data_encoding.rb', line 204 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
188 189 190 191 192 193 |
# File 'lib/net/imap/data_encoding.rb', line 188 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
196 197 198 199 200 201 |
# File 'lib/net/imap/data_encoding.rb', line 196 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
179 180 181 182 183 184 185 |
# File 'lib/net/imap/data_encoding.rb', line 179 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
161 162 163 164 165 166 167 |
# File 'lib/net/imap/data_encoding.rb', line 161 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
170 171 172 173 174 175 176 |
# File 'lib/net/imap/data_encoding.rb', line 170 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 |