Class: GmailBritta::FilterSet

Inherits:
Object
  • Object
show all
Defined in:
lib/gmail-britta/filter_set.rb

Defined Under Namespace

Classes: Delegate

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ FilterSet

Returns a new instance of FilterSet


3
4
5
6
7
8
9
10
# File 'lib/gmail-britta/filter_set.rb', line 3

def initialize(opts={})
  @filters = []
  @me = opts[:me] || 'me'
  @logger = opts[:logger] || allocate_logger
  @author = opts[:author] || {}
  @author[:name] ||= "Andreas Fuchs"
  @author[:email] ||= "[email protected]"
end

Instance Attribute Details

#filtersObject

Currently defined filters


17
18
19
# File 'lib/gmail-britta/filter_set.rb', line 17

def filters
  @filters
end

#loggerObject

The logger currently being used for debug output


25
26
27
# File 'lib/gmail-britta/filter_set.rb', line 25

def logger
  @logger
end

#meObject

The list of emails that belong to the user running this GmailBritta::FilterSet definition


21
22
23
# File 'lib/gmail-britta/filter_set.rb', line 21

def me
  @me
end

Instance Method Details

#generateString

Generate ATOM XML for the defined filter set and return it as a String.

Returns:

  • (String)

    the generated XML, ready for importing into Gmail.


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gmail-britta/filter_set.rb', line 36

def generate
  engine = Haml::Engine.new(<<-ATOM)
!!! XML
%feed{:xmlns => 'http://www.w3.org/2005/Atom', 'xmlns:apps' => 'http://schemas.google.com/apps/2006'}
  %title Mail Filters
  %id tag:mail.google.com,2008:filters:
  %updated #{Time.now.utc.iso8601}
  %author
%name #{@author[:name]}
%email #{@author[:email]}
  - filters.each do |filter|
!= filter.generate_xml
ATOM
  engine.render(self)
end

#rules { ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Run the block that defines the filters in Delegate's instance_eval. This method will typically only be called by GmailBritta.filterset.

Yields:

  • the filter definition block in Delegate's instance_eval.


30
31
32
# File 'lib/gmail-britta/filter_set.rb', line 30

def rules(&block)
  Delegate.new(self, :logger => @logger).perform(&block)
end