diff options
author | mms <git@sapka.me> | 2024-11-18 20:59:45 +0100 |
---|---|---|
committer | mms <git@sapka.me> | 2024-11-18 21:00:08 +0100 |
commit | 8004fd7f9fc91ce9ec02b1b8e8eac639b17d0eb8 (patch) | |
tree | 88438de57c315eba59791611f11260f005610cda | |
parent | 786a3ae9ffd25cc6482fbb7c6358afc3421abfb3 (diff) |
feat: order
-rw-r--r-- | .ruby-version | 1 | ||||
-rw-r--r-- | lib/chotto/.messages.rb.swp | bin | 0 -> 12288 bytes | |||
-rw-r--r-- | lib/chotto/messages.rb | 18 | ||||
-rw-r--r-- | spec/lib/.messages_spec.rb.swp | bin | 0 -> 12288 bytes | |||
-rw-r--r-- | spec/lib/messages_spec.rb | 6 |
5 files changed, 23 insertions, 2 deletions
diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index bec3a35..0000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -system diff --git a/lib/chotto/.messages.rb.swp b/lib/chotto/.messages.rb.swp Binary files differnew file mode 100644 index 0000000..d31c1b5 --- /dev/null +++ b/lib/chotto/.messages.rb.swp 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)) diff --git a/spec/lib/.messages_spec.rb.swp b/spec/lib/.messages_spec.rb.swp Binary files differnew file mode 100644 index 0000000..98cda14 --- /dev/null +++ b/spec/lib/.messages_spec.rb.swp diff --git a/spec/lib/messages_spec.rb b/spec/lib/messages_spec.rb index 7550991..79551b7 100644 --- a/spec/lib/messages_spec.rb +++ b/spec/lib/messages_spec.rb @@ -68,4 +68,10 @@ RSpec.describe Chotto::Messages do .to eq(' (from:baltar@battlestar.com) or (from:adama@battestar.com) and (ship:battlestar) or (ship:pegasus)') } end + + context 'sorting order' do + it { expect(subject.filter('from:baltar@battlestar.com').order).to eq('oldest_first') } + it { expect(subject.filter('from:baltar@battlestar.com').newest_first.order).to eq('newest_first') } + it { expect(subject.filter('from:baltar@battlestar.com').newest_first.oldest_first.order).to eq('oldest_first') } + end end |