Class: Doing::Item

Inherits:
Object
  • Object
show all
Includes:
Color
Defined in:
lib/doing/item.rb

Overview

This class describes a single WWID item

Constant Summary

Constants included from Color

Color::ATTRIBUTES, Color::ATTRIBUTE_NAMES, Color::COLORED_REGEXP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Color

attributes, coloring?, #support?, #uncolor

Constructor Details

#initialize(date, title, section, note = nil) ⇒ Item

Initialize an item with date, title, section, and optional note

Parameters:

  • date (Time)

    The item's start date

  • title (String)

    The title

  • section (String)

    The section to which the item belongs

  • note (Array or String) (defaults to: nil)

    The note (optional)

Instance Attribute Details

#dateObject

Returns the value of attribute date.

#noteObject

Returns the value of attribute note.

#sectionObject

Returns the value of attribute section.

#titleObject

Returns the value of attribute title.

Instance Method Details

#calculate_end_date(opt) ⇒ Object

#durationObject

If the entry doesn't have a @done date, return the elapsed time

#end_dateTime

Get the value of the item's @done tag

Returns:

  • (Time)

    @done value

#equal?(other) ⇒ Boolean

Test for equality between items

Parameters:

  • other (Item)

    The other item

Returns:

  • (Boolean)

    is equal?

#expand_date_tags(additional_tags = nil) ⇒ Object

Updates the title of the Item by expanding natural language dates within configured date tags (tags whose value is expected to be a date)

Parameters:

  • additional_tags (defaults to: nil)

    An array of additional tag names to consider dates

#highlight_search(search, distance: nil, negate: false, case_type: nil) ⇒ Object

#idString

Generate a hash that represents the entry

Returns:

#ignore_case(search, case_type) ⇒ Boolean

Determine if case should be ignored for searches

Parameters:

  • search (String)

    The search string

  • case_type (Symbol)

    The case type

Returns:

  • (Boolean)

    case should be ignored

#intervalObject

Get the difference between the item's start date and the value of its @done tag (if present)

Returns:

  • Interval in seconds

#move_to(new_section, label: true, log: true) ⇒ Object

Move item from current section to destination section

Parameters:

  • new_section (String)

    The destination section

  • label (Boolean) (defaults to: true)

    add @from(original section) tag

  • log (Boolean) (defaults to: true)

    log this action

Returns:

  • nothing

#overlapping_time?(item_b) ⇒ Boolean

Test if the interval between start date and @done value overlaps with another item's

Parameters:

  • item_b (Item)

    The item to compare

Returns:

  • (Boolean)

    overlaps?

#same_time?(item_b) ⇒ Boolean

Test if two items occur at the same time (same start date and equal duration)

Parameters:

  • item_b (Item)

    The item to compare

Returns:

  • (Boolean)

    is equal?

#search(search, distance: nil, negate: false, case_type: nil) ⇒ Boolean

Test if item matches search string

Parameters:

  • search (String)

    The search string

  • negate (Boolean) (defaults to: false)

    negate results

  • case_type (Symbol) (defaults to: nil)

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

Returns:

  • (Boolean)

    matches search criteria

#should_finish?Boolean

Test if item is included in never_finish config and thus should not receive a @done tag

Returns:

  • (Boolean)

    item should receive @done tag

#should_time?Boolean

Test if item is included in never_time config and thus should not receive a date on the @done tag

Returns:

  • (Boolean)

    item should receive @done date

#tag(tags, **options) ⇒ Object

Add (or remove) tags from the title of the item

Parameters:

  • tags (Array)

    The tags to apply

  • options

    Additional options

Options Hash (**options):

  • :date (Boolean)

    Include timestamp?

  • :single (Boolean)

    Log as a single change?

  • :value (String)

    A value to include as @tag(value)

  • :remove (Boolean)

    if true remove instead of adding

  • :rename_to (String)

    if not nil, rename target tag to this tag name

  • :regex (Boolean)

    treat target tag string as regex pattern

  • :force (Boolean)

    with rename_to, add tag if it doesn't exist

#tag_arrayArray

convert tags on item to an array with @ symbols removed

Returns:

  • (Array)

    array of tags

#tag_values?(queries, bool = :and, negate: false) ⇒ Boolean

Test if item matches tag values

Parameters:

  • queries (Array)

    The tag value queries to test

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

    The boolean to use for multiple tags (:and, :or, :not)

  • negate (Boolean) (defaults to: false)

    negate the result?

Returns:

  • (Boolean)

    true if tag/bool combination passes

#tagsArray

Get a list of tags on the item

Returns:

  • (Array)

    array of tags (no values)

#tags?(tags, bool = :and, negate: false) ⇒ Boolean

Test if item contains tag(s)

Parameters:

  • tags (Array or String)

    The tags to test. Can be an array or a comma-separated string.

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

    The boolean to use for multiple tags (:and, :or, :not)

  • negate (Boolean) (defaults to: false)

    negate the result?

Returns:

  • (Boolean)

    true if tag/bool combination passes

#to_pretty(elements: %i[date title section]) ⇒ Object

outputs a colored string with relative date and highlighted tags

Returns:

  • Pretty representation of the object.

#to_sObject

outputs item in Doing file format, including leading tab