Class: Gmail::Labels

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/gmail/labels.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Labels) initialize(connection)

A new instance of Labels



7
8
9
# File 'lib/gmail/labels.rb', line 7

def initialize(connection)
  @connection = connection
end

Instance Attribute Details

- (Object) connection (readonly) Also known as: conn

Returns the value of attribute connection



4
5
6
# File 'lib/gmail/labels.rb', line 4

def connection
  @connection
end

Instance Method Details

- (Object) all Also known as: list, to_a

Get list of all defined labels.



12
13
14
15
16
17
# File 'lib/gmail/labels.rb', line 12

def all
  (conn.list("", "%")+conn.list("[Gmail]/", "%")).inject([]) do |labels,label|
    label[:name].each_line {|l| labels << Net::IMAP.decode_utf7(l) }
    labels 
  end
end

- (Object) create(label) Also known as: new, add

Creates given label in your account.



32
33
34
# File 'lib/gmail/labels.rb', line 32

def create(label)
  !!conn.create(Net::IMAP.encode_utf7(label)) rescue false
end

- (Object) delete(label) Also known as: remove

Deletes given label from your account.



39
40
41
# File 'lib/gmail/labels.rb', line 39

def delete(label)
  !!conn.delete(Net::IMAP.encode_utf7(label)) rescue false
end

- (Object) each(*args, &block)



21
22
23
# File 'lib/gmail/labels.rb', line 21

def each(*args, &block)
  all.each(*args, &block)
end

- (Boolean) exists?(label) Also known as: exist?

Returns true when given label defined.

Returns:

  • (Boolean)


26
27
28
# File 'lib/gmail/labels.rb', line 26

def exists?(label)
  all.include?(Net::IMAP.encode_utf7(label))
end

- (Object) inspect



44
45
46
# File 'lib/gmail/labels.rb', line 44

def inspect
  "#<Gmail::Labels#{'0x%04x' % (object_id << 1)}>"
end