diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chotto/.messages.rb.swp | bin | 0 -> 12288 bytes | |||
-rw-r--r-- | lib/chotto/messages.rb | 18 |
2 files changed, 17 insertions, 1 deletions
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)) |