Class: WorkingClass::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/working_class/task.rb

Overview

A basic represantation of a Task

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Task

Initializes a new task object with a name, and options

Parameters:

  • name (String)

    the task name

  • options (Hash) (defaults to: {})

    an options hash

Options Hash (options):

  • :is_finished (Boolean) — default: false

    true if the task is finished

  • :date (Date) — default: nil

    the date when the task is due

  • :reminder (DateTime) — default: nil

    a DateTime with a reminder



28
29
30
31
32
33
34
# File 'lib/working_class/task.rb', line 28

def initialize name, options = {}
  options = {is_finished: false, date: nil, reminder: nil}.merge(options)
  @name = name
  @is_finished = options[:is_finished]
  @date = options[:date]
  @reminder = options[:reminder]
end

Instance Attribute Details

#dateDate (readonly)

the day the task is due

Returns:

  • (Date)

    the current value of date



9
10
11
# File 'lib/working_class/task.rb', line 9

def date
  @date
end

#is_finishedBoolean (readonly) Also known as: is_finished?, finished?

true if the task is finished

Returns:

  • (Boolean)

    the current value of is_finished



9
10
11
# File 'lib/working_class/task.rb', line 9

def is_finished
  @is_finished
end

#nameString (readonly)

the task name

Returns:

  • (String)

    the current value of name



9
10
11
# File 'lib/working_class/task.rb', line 9

def name
  @name
end

#reminderDateTime (readonly)

a DateTime with a reminder

Returns:

  • (DateTime)

    the current value of reminder



9
10
11
# File 'lib/working_class/task.rb', line 9

def reminder
  @reminder
end

Instance Method Details

#is_tomorrowBoolean Also known as: is_tomorrow?, tomorrow?

TODO:

add example

TODO:

add example

Returns true if the task is due tomorrow

A Task without a date is always due tomorrow. A finished task is never due tomorrow.

Returns:

  • (Boolean)

    true if the task is due tomorrow



67
68
69
70
71
72
73
74
75
# File 'lib/working_class/task.rb', line 67

def is_tomorrow
  if @is_finished
    false
  elsif date.nil?
    true
  else
    Date.today + 1 == @date
  end
end

#is_upcomingBoolean Also known as: is_upcoming?, upcoming?

TODO:

add example

TODO:

add example

Returns true if the task is upcoming

A Task without a date is always upcoming. A finished task is never upcoming.

Returns:

  • (Boolean)

    true if the task is upcoming



45
46
47
48
49
50
51
52
53
# File 'lib/working_class/task.rb', line 45

def is_upcoming
  if @is_finished
    false
  elsif !@date.nil?
    Date.today <= @date
  else
    true
  end
end