Class: TodoLint::DueDate

Inherits:
Object
  • Object
show all
Defined in:
lib/todo_lint/due_date.rb

Overview

When is this todo actually due? When ought we be reminded of this one?

Constant Summary collapse

DATE_PATTERN =
/(\d{4})-(\d{2})-(\d{2})/
ANNOTATION_PATTERN =
/\(#{DATE_PATTERN}\)/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date) ⇒ DueDate

Take a simple date object and imbue it with meaning

Examples:

DueDate.new(Date.today)


54
55
56
# File 'lib/todo_lint/due_date.rb', line 54

def initialize(date)
  @to_date = date
end

Instance Attribute Details

#to_dateDate (readonly)

The actual date object when something is due

Examples:

DueDate.new(Date.today).to_date == Date.today #=> true

Returns:

  • (Date)


48
49
50
# File 'lib/todo_lint/due_date.rb', line 48

def to_date
  @to_date
end

Class Method Details

.from_annotation(date) ⇒ DueDate

Parse the date from the todo comment’s due date annotation

Examples:

DueDate.from_annotation("(2015-04-14)")

Returns:

  • (DueDate)

    if the annotation is formatted properly

Raises:

  • (ArgumentError)

    if the annotation is not formatted properly



25
26
27
# File 'lib/todo_lint/due_date.rb', line 25

def self.from_annotation(date)
  from_pattern(date, ANNOTATION_PATTERN)
end

.from_config_file(date) ⇒ DueDate

Parse the date from the todo_lint configuration file

Examples:

DueDate.from_config_file("2015-04-14")

Returns:

  • (DueDate)

    if the annotation is formatted properly

Raises:

  • (ArgumentError)

    if the annotation is not formatted properly



15
16
17
# File 'lib/todo_lint/due_date.rb', line 15

def self.from_config_file(date)
  from_pattern(date, DATE_PATTERN)
end

Instance Method Details

#overdue?Boolean

Is this due date in the past?

Examples:

due_date.overdue? #=> true

Returns:

  • (Boolean)


63
64
65
# File 'lib/todo_lint/due_date.rb', line 63

def overdue?
  Date.today > to_date
end