aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormms <git@sapka.me>2024-11-18 20:59:45 +0100
committermms <git@sapka.me>2024-11-18 21:00:08 +0100
commit8004fd7f9fc91ce9ec02b1b8e8eac639b17d0eb8 (patch)
tree88438de57c315eba59791611f11260f005610cda /lib
parent786a3ae9ffd25cc6482fbb7c6358afc3421abfb3 (diff)
feat: order
Diffstat (limited to 'lib')
-rw-r--r--lib/chotto/.messages.rb.swpbin0 -> 12288 bytes
-rw-r--r--lib/chotto/messages.rb18
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/chotto/.messages.rb.swp b/lib/chotto/.messages.rb.swp
new file mode 100644
index 0000000..d31c1b5
--- /dev/null
+++ b/lib/chotto/.messages.rb.swp
Binary files differ
diff --git a/lib/chotto/messages.rb b/lib/chotto/messages.rb
index 7326148..0d48c72 100644
--- a/lib/chotto/messages.rb
+++ b/lib/chotto/messages.rb
@@ -5,6 +5,9 @@ module Chotto
AND_CONJUCTION = :and
OR_CONJUCTION = :or
DEFAULT_CONJUCTION = AND_CONJUCTION
+ OLDEST_FIRST_ORDER = 'oldest_first'
+ NEWEST_FIRST_ORDER = 'newest_first'
+ DEFAULT_ORDER = OLDEST_FIRST_ORDER
Token = Struct.new(:conjuction, :field, :value, :messages) do
def to_query
@@ -42,7 +45,7 @@ module Chotto
end
end
- attr_accessor :query, :current_conjuction, :token_count
+ attr_accessor :query, :current_conjuction, :token_count, :order
attr_reader :db
def initialize(db:)
@@ -50,6 +53,7 @@ module Chotto
@query = []
@current_conjuction = AND_CONJUCTION
@token_count = 0
+ @order = DEFAULT_ORDER
end
def or
@@ -73,6 +77,18 @@ module Chotto
self
end
+ def newest_first
+ @order = NEWEST_FIRST_ORDER
+
+ self
+ end
+
+ def oldest_first
+ @order = OLDEST_FIRST_ORDER
+
+ self
+ end
+
def each
db.search_messages(query_string).each do |msg|
yield(Message.new(msg: msg))