Class: Mailscope::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/mailscope/query.rb

Overview

Filters the in-memory message list. Small enough to stay honest about what it does: no index, just a scan over metadata that is already loaded.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(messages, mailbox: nil, term: nil, only: nil) ⇒ Query

Returns a new instance of Query.



9
10
11
12
13
14
# File 'lib/mailscope/query.rb', line 9

def initialize(messages, mailbox: nil, term: nil, only: nil)
  @messages = messages
  @mailbox  = mailbox.to_s.downcase.presence
  @term     = term.to_s.strip.presence
  @only     = only.to_s.presence
end

Instance Attribute Details

#mailboxObject (readonly)

Returns the value of attribute mailbox.



7
8
9
# File 'lib/mailscope/query.rb', line 7

def mailbox
  @mailbox
end

#messagesObject (readonly)

Returns the value of attribute messages.



7
8
9
# File 'lib/mailscope/query.rb', line 7

def messages
  @messages
end

#onlyObject (readonly)

Returns the value of attribute only.



7
8
9
# File 'lib/mailscope/query.rb', line 7

def only
  @only
end

#termObject (readonly)

Returns the value of attribute term.



7
8
9
# File 'lib/mailscope/query.rb', line 7

def term
  @term
end

Instance Method Details

#filtered?Boolean

Returns:

  • (Boolean)


20
# File 'lib/mailscope/query.rb', line 20

def filtered? = !(mailbox.nil? && term.nil? && only.nil?)

#resultsObject



16
17
18
# File 'lib/mailscope/query.rb', line 16

def results
  @results ||= messages.select { |m| matches_mailbox?(m) && matches_only?(m) && matches_term?(m) }
end