Class: Gmail::Labels
Instance Attribute Summary collapse
-
#connection ⇒ Object
(also: #conn)
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
-
#all ⇒ Object
(also: #list, #to_a)
Get list of all defined labels.
-
#create(label) ⇒ Object
(also: #new, #add)
Creates given label in your account.
-
#delete(label) ⇒ Object
(also: #remove)
Deletes given label from your account.
- #each(*args, &block) ⇒ Object
-
#exists?(label) ⇒ Boolean
(also: #exist?)
Returns
true
when given label defined. -
#initialize(connection) ⇒ Labels
constructor
A new instance of Labels.
- #inspect ⇒ Object
Constructor Details
#initialize(connection) ⇒ Labels
Returns a new instance of Labels.
7 8 9 |
# File 'lib/gmail/labels.rb', line 7 def initialize(connection) @connection = connection end |
Instance Attribute Details
#connection ⇒ Object (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
#all ⇒ Object 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 |
#create(label) ⇒ Object 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 |
#delete(label) ⇒ Object 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 |
#each(*args, &block) ⇒ Object
21 22 23 |
# File 'lib/gmail/labels.rb', line 21 def each(*args, &block) all.each(*args, &block) end |
#exists?(label) ⇒ Boolean Also known as: exist?
Returns true
when given label defined.
26 27 28 |
# File 'lib/gmail/labels.rb', line 26 def exists?(label) all.include?(Net::IMAP.encode_utf7(label)) end |
#inspect ⇒ Object
44 45 46 |
# File 'lib/gmail/labels.rb', line 44 def inspect "#<Gmail::Labels#{'0x%04x' % (object_id << 1)}>" end |