Class: GMail::Tag

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/gmail/tag.rb

Overview

Handles GMail tags

Used when creating a mailbox based on the tag itself, after replacing the “/” used by GMail by “-”

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Tag) initialize(label)

Create a new tag from the parameter

Tag.new("the/tag") # => a new tag

Raises:

  • (ArgumentError)


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

def initialize(label)
  @label = label
  raise ArgumentError if label.nil?
end

Instance Attribute Details

- (Object) label (readonly)

label tag's name



16
17
18
# File 'lib/gmail/tag.rb', line 16

def label
  @label
end

Instance Method Details

- (Object) <=>(e)

comparison

Parameters:



54
55
56
# File 'lib/gmail/tag.rb', line 54

def <=>(e)
  @label <=> e.label
end

- (True|False) match(tags)

Match the tag against another one or multiple values If @label is “Bar” then

self.match("Bar") # => true
self.match(["Foo", "Bar"]) # => true
self.match(["tag1", "tag2"]) # => false

Parameters:

  • tags

    string or array representing a tag or list thereof

Returns:

  • (True|False)

    rematching result



42
43
44
45
46
47
48
49
50
# File 'lib/gmail/tag.rb', line 42

def match(tags)
  t = tags.dup
  if tags.class == String
    t = [ tags ]
  end
  flag = false
  t.each{|e| flag = @label == e ? true : false }
  flag
end

- (String) to_s

Generate a FS-compatible label If @label is “Foo/Bar”

self.to_s # => "Foo-Bar"

Returns:

  • (String)

    the converted label



30
31
32
# File 'lib/gmail/tag.rb', line 30

def to_s
  @label.gsub(%r{/}, '-')
end