Class: Net::IMAP::PartialRange

Inherits:
CommandData show all
Defined in:
lib/net/imap/command_data.rb

Overview

:nodoc:

Constant Summary collapse

POS_RANGE =
1..uint32_max
NEG_RANGE =
-uint32_max..-1
Positive =
->{ (_1 in Range) and POS_RANGE.cover?(_1) }
Negative =
->{ (_1 in Range) and NEG_RANGE.cover?(_1) }

Instance Method Summary collapse

Methods inherited from CommandData

#validate

Constructor Details

#initialize(data:) ⇒ PartialRange

Returns a new instance of PartialRange.



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/net/imap/command_data.rb', line 163

def initialize(data:)
  min, max = case data
  in Range
    data.minmax.map { Integer _1 }
  in ResponseParser::Patterns::PARTIAL_RANGE
    data.split(":").map { Integer _1 }.minmax
  else
    raise ArgumentError, "invalid partial range input: %p" % [data]
  end
  data = min..max
  unless data in Positive | Negative
    raise ArgumentError, "invalid partial-range: %p" % [data]
  end
  super
rescue TypeError, RangeError
  raise ArgumentError, "expected range min/max to be Integers"
end

Instance Method Details

#formattedObject



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

def formatted = "%d:%d" % data.minmax

#send_data(imap, tag) ⇒ Object



183
184
185
# File 'lib/net/imap/command_data.rb', line 183

def send_data(imap, tag)
  imap.__send__(:put_string, formatted)
end