From 8004fd7f9fc91ce9ec02b1b8e8eac639b17d0eb8 Mon Sep 17 00:00:00 2001 From: mms Date: Mon, 18 Nov 2024 20:59:45 +0100 Subject: feat: order --- lib/chotto/.messages.rb.swp | Bin 0 -> 12288 bytes lib/chotto/messages.rb | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 lib/chotto/.messages.rb.swp (limited to 'lib') diff --git a/lib/chotto/.messages.rb.swp b/lib/chotto/.messages.rb.swp new file mode 100644 index 0000000..d31c1b5 Binary files /dev/null and b/lib/chotto/.messages.rb.swp 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)) -- cgit v1.2.3