class GmailBritta::FilterSet

Attributes

logger[RW]

The logger currently being used for debug output @see GmailBritta.filterset

me[RW]

The list of emails that belong to the user running this {FilterSet} definition @see GmailBritta.filterset

Public Class Methods

new(opts={}) click to toggle source
# 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] ||= "asf@boinkor.net"
end

Public Instance Methods

generate() click to toggle source

Generate ATOM XML for the defined filter set and return it as a String. @return [String] the generated XML, ready for importing into Gmail.

# 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(&block) click to toggle source

Run the block that defines the filters in {Delegate}'s `instance_eval`. This method will typically only be called by {GmailBritta.filterset}. @api private @yield the filter definition block in {Delegate}'s instance_eval.

# File lib/gmail-britta/filter_set.rb, line 30
def rules(&block)
  Delegate.new(self, :logger => @logger).perform(&block)
end

Private Instance Methods

allocate_logger() click to toggle source
# File lib/gmail-britta/filter_set.rb, line 79
def allocate_logger
  logger = Logger.new(STDERR)
  logger.level = Logger::WARN
  logger
end