Sha256: b4baa2178d9e5930aa5d772da7d38ec5b6b2b5e66c18a0fc93bdb1fe0a5474e3

Contents?: true

Size: 1.96 KB

Versions: 21

Compression:

Stored size: 1.96 KB

Contents

# frozen_string_literal: true

module Doing
  class Items < Array
    # Get a new Items object containing only items in a
    # specified section
    #
    # @param      section  [String] section title
    #
    # @return     [Items] Array of items
    #
    def in_section(section)
      if section =~ /^all$/i
        dup
      else
        items = Items.new.concat(select { |item| !item.nil? && item.section == section })
        items.add_section(section, log: false)
        items
      end
    end

    ##
    ## Search Items for a string (title and note)
    ##
    ## @param      query      [String] The query
    ## @param      case_type  [Symbol] The case type
    ##                        (:smart, :sensitive, :ignore)
    ##
    ## @return     [Items] array of items matching search
    ##
    def search(query, case_type: :smart)
      WWID.new.fuzzy_filter_items(self, query, case_type: case_type)
    end

    ##
    ## Search items by tags
    ##
    ## @param      tags  [Array,String] The tags by which to
    ##                   filter
    ## @param      bool  [Symbol] The bool with which to
    ##                   combine multiple tags
    ##
    ## @return     [Items] array of items matching tag filter
    ##
    def tagged(tags, bool: :and)
      WWID.new.filter_items(self, opt: { tag: tags, bool: bool })
    end

    ##
    ## Filter Items by date. String arguments will be
    ## chronified
    ##
    ## @param      start   [Time,String] Filter items after
    ##                     this date
    ## @param      finish  [Time,String] Filter items before
    ##                     this date
    ##
    ## @return     [Items] array of items with dates between
    ##             targets
    ##
    def between_dates(start, finish)
      start = start.chronify(guess: :begin, future: false) if start.is_a?(String)
      finish = finish.chronify(guess: :end) if finish.is_a?(String)
      WWID.new.filter_items(self, opt: { date_filter: [start, finish] })
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
doing-2.1.65 lib/doing/items/filter.rb
doing-2.1.64 lib/doing/items/filter.rb
doing-2.1.63 lib/doing/items/filter.rb
doing-2.1.62 lib/doing/items/filter.rb
doing-2.1.61 lib/doing/items/filter.rb
doing-2.1.60 lib/doing/items/filter.rb
doing-2.1.58 lib/doing/items/filter.rb
doing-2.1.57 lib/doing/items/filter.rb
doing-2.1.56 lib/doing/items/filter.rb
doing-2.1.55 lib/doing/items/filter.rb
doing-2.1.54 lib/doing/items/filter.rb
doing-2.1.52 lib/doing/items/filter.rb
doing-2.1.49 lib/doing/items/filter.rb
doing-2.1.48 lib/doing/items/filter.rb
doing-2.1.47 lib/doing/items/filter.rb
doing-2.1.46 lib/doing/items/filter.rb
doing-2.1.45 lib/doing/items/filter.rb
doing-2.1.44 lib/doing/items/filter.rb
doing-2.1.43 lib/doing/items/filter.rb
doing-2.1.42 lib/doing/items/filter.rb