Class: Doing::Items

Inherits:
Array show all
Defined in:
lib/doing/items/items.rb,
lib/doing/items/util.rb,
lib/doing/items/filter.rb,
lib/doing/items/modify.rb,
lib/doing/items/sections.rb

Overview

A collection of Item objects

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Array

#good?, #utf8

Methods included from ChronifyArray

#time_string, #to_abbr, #to_natural, #to_years

Constructor Details

#initializeItems

Returns a new instance of Items.

Instance Attribute Details

#sectionsObject

Returns the value of attribute sections.

Instance Method Details

#add_section(section, log: false) ⇒ Object

Add a new section to the sections array. Accepts either a Section object, or a title string that will be converted into a Section.

Parameters:

  • section (Section)

    The section to add. A String value will be converted to Section automatically.

  • log (Boolean) (defaults to: false)

    Add a log message notifying the user about the creation of the section.

Returns:

  • nothing

#all_tagsArray

Get all tags on Items in self

Returns:

  • (Array)

    array of tags

#between_dates(start, finish) ⇒ Items

Filter Items by date. String arguments will be chronified

Parameters:

  • start (Time, String)

    Filter items after this date

  • finish (Time, String)

    Filter items before this date

Returns:

  • (Items)

    array of items with dates between targets

#dedup(match_section: true) ⇒ Items

Remove duplicated entries. Duplicate entries must have matching start date, title, note, and section

Returns:

  • (Items)

    Items array with duplicate entries removed

#dedup!(match_section: true) ⇒ Object

See Also:

#delete(item) ⇒ Object

Create a deep copy of Items

def clone Marshal.load(Marshal.dump(self)) end

#delete_item(item, single: false) ⇒ Object

Delete an item from the index

Parameters:

  • item

    The item

#delete_section(section, log: false) ⇒ Object

Raises:

  • (DoingRuntimeError)

#diff(items) ⇒ Hash

Return Items containing items that don't exist in receiver

Parameters:

  • items (Items)

    Receiver

Returns:

  • (Hash)

    Hash of added and deleted items

#find_id(id) ⇒ Object

Find an item by ID

Parameters:

  • id

    The identifier to match

#guess_section(frag, distance: 2) ⇒ Section

Return the best section match for a search query

Parameters:

  • frag

    The search query

  • distance (defaults to: 2)

    The distance apart characters can be (fuzziness)

Returns:

  • (Section)

    (first) matching section object

#in_section(section) ⇒ Items

Get a new Items object containing only items in a specified section

Parameters:

  • section (String)

    section title

Returns:

  • (Items)

    Array of items

#include?(item, match_section: true) ⇒ Boolean

Test if self includes Item

Parameters:

  • item (Item)

    The item to search for

  • match_section (Boolean) (defaults to: true)

    Section must match

Returns:

  • (Boolean)

    True if Item exists

#index_for_id(id) ⇒ Object

Return the index for an entry matching ID

Parameters:

  • id

    The identifier to match

#search(query, case_type: :smart) ⇒ Items

Search Items for a string (title and note)

Parameters:

  • query (String)

    The query

  • case_type (Symbol) (defaults to: :smart)

    The case type (:smart, :sensitive, :ignore)

Returns:

  • (Items)

    array of items matching search

#section?(section) ⇒ Boolean

Test if section already exists

Parameters:

  • section (String)

    section title

Returns:

  • (Boolean)

    true if section exists

#section_titlesArray

List sections, title only

Returns:

  • (Array)

    section titles

#tagged(tags, bool: :and) ⇒ Items

Search items by tags

Parameters:

  • tags (Array, String)

    The tags by which to filter

  • bool (Symbol) (defaults to: :and)

    The bool with which to combine multiple tags

Returns:

  • (Items)

    array of items matching tag filter

#to_sObject

Output sections and items in Doing file format

#update_item(old_item, new_item) ⇒ Object

Update an item in the index with a modified item

Parameters:

  • old_item

    The old item

  • new_item

    The new item

Raises:

  • (ItemNotFound)