Iterates over keys and objects in a weakly referenced object
Returns the field value as specified by header
.
With the single argument header
, returns the field value for that header (first found):
source = "Name,Name,Name\nFoo,Bar,Baz\n" table = CSV.parse(source, headers: true) row = table[0] row.fetch('Name') # => "Foo"
Raises exception KeyError
if the header does not exist.
With arguments header
and default
given, returns the field value for the header (first found) if the header exists, otherwise returns default
:
source = "Name,Name,Name\nFoo,Bar,Baz\n" table = CSV.parse(source, headers: true) row = table[0] row.fetch('Name', '') # => "Foo" row.fetch(:nosuch, '') # => ""
With argument header
and a block given, returns the field value for the header (first found) if the header exists; otherwise calls the block and returns its return value:
source = "Name,Name,Name\nFoo,Bar,Baz\n" table = CSV.parse(source, headers: true) row = table[0] row.fetch('Name') {|header| fail 'Cannot happen' } # => "Foo" row.fetch(:nosuch) {|header| "Header '#{header} not found'" } # => "Header 'nosuch not found'"
Yields each pair of the row as header and field tuples (much like iterating over a Hash
). This method returns the row for chaining.
If no block is given, an Enumerator
is returned.
Support for Enumerable
.
Calls the block with each row or column; returns self
.
When the access mode is :row
or :col_or_row
, calls the block with each CSV::Row object:
source = "Name,Value\nfoo,0\nbar,1\nbaz,2\n" table = CSV.parse(source, headers: true) table.by_row! # => #<CSV::Table mode:row row_count:4> table.each {|row| p row }
Output:
#<CSV::Row "Name":"foo" "Value":"0"> #<CSV::Row "Name":"bar" "Value":"1"> #<CSV::Row "Name":"baz" "Value":"2">
When the access mode is :col
, calls the block with each column as a 2-element array containing the header and an Array of column fields:
table.by_col! # => #<CSV::Table mode:col row_count:4> table.each {|column_data| p column_data }
Output:
["Name", ["foo", "bar", "baz"]] ["Value", ["0", "1", "2"]]
Returns a new Enumerator if no block is given:
table.each # => #<Enumerator: #<CSV::Table mode:col row_count:4>:each>
Matches addr
against this entry.
Matches addr
against each ACLEntry
in this list.
Sends a PATCH request to the path
and gets a response, as an HTTPResponse
object.
Sends a PROPPATCH request to the path
and gets a response, as an HTTPResponse
object.
Sends a CHECK command to request a checkpoint of the currently selected mailbox. This performs implementation-specific housekeeping; for instance, reconciling the mailbox’s in-memory and on-disk state.
Sends a SEARCH command to search the mailbox for messages that match the given searching criteria, and returns message sequence numbers. keys
can either be a string holding the entire search string, or a single-dimension array of search keywords and arguments. The following are some common search criteria; see [IMAP] section 6.4.4 for a full list.
a set of message sequence numbers. ‘,’ indicates an interval, ‘:’ indicates a range. For instance, ‘2,10:12,15’ means “2,10,11,12,15”.
messages with an internal date strictly before <date>. The date argument has a format similar to 8-Aug-2002.
messages that contain <string> within their body.
messages containing <string> in their CC field.
messages that contain <string> in their FROM field.
messages with the Recent, but not the Seen, flag set.
negate the following search key.
“or” two search keys together.
messages with an internal date exactly equal to <date>, which has a format similar to 8-Aug-2002.
messages with an internal date on or after <date>.
messages with <string> in their subject.
messages with <string> in their TO field.
For example:
p imap.search(["SUBJECT", "hello", "NOT", "NEW"]) #=> [1, 6, 7, 8]
Sends a FETCH command to retrieve data associated with a message in the mailbox.
The set
parameter is a number or a range between two numbers, or an array of those. The number is a message sequence number, where -1 represents a ‘*’ for use in range notation like 100..-1 being interpreted as ‘100:*’. Beware that the exclude_end?
property of a Range
object is ignored, and the contents of a range are independent of the order of the range endpoints as per the protocol specification, so 1…5, 5..1 and 5…1 are all equivalent to 1..5.
attr
is a list of attributes to fetch; see the documentation for Net::IMAP::FetchData
for a list of valid attributes.
The return value is an array of Net::IMAP::FetchData
or nil (instead of an empty array) if there is no matching message.
For example:
p imap.fetch(6..8, "UID") #=> [#<Net::IMAP::FetchData seqno=6, attr={"UID"=>98}>, \\ #<Net::IMAP::FetchData seqno=7, attr={"UID"=>99}>, \\ #<Net::IMAP::FetchData seqno=8, attr={"UID"=>100}>] p imap.fetch(6, "BODY[HEADER.FIELDS (SUBJECT)]") #=> [#<Net::IMAP::FetchData seqno=6, attr={"BODY[HEADER.FIELDS (SUBJECT)]"=>"Subject: test\r\n\r\n"}>] data = imap.uid_fetch(98, ["RFC822.SIZE", "INTERNALDATE"])[0] p data.seqno #=> 6 p data.attr["RFC822.SIZE"] #=> 611 p data.attr["INTERNALDATE"] #=> "12-Oct-2000 22:40:59 +0900" p data.attr["UID"] #=> 98
Starts a POP3
session and iterates over each POPMail
object, yielding it to the block
. This method is equivalent to:
Net::POP3.start(address, port, account, password) do |pop| pop.each_mail do |m| yield m end end
This method raises a POPAuthenticationError
if authentication fails.
Net::POP3.foreach('pop.example.com', 110, 'YourAccount', 'YourPassword') do |m| file.write m.pop m.delete if $DELETE end
Searches key
in id
list. The result is returned or yielded if a block is given. If it isn’t found, nil is returned.
Completion
for hash key.
Iterates the given block for each prime number.
Fetches item k
from the tuple.
Iterate through the tuple, yielding the index or key, and the value, thus ensuring arrays are iterated similarly to hashes.