Class: Mastodon::Todo

Inherits:
Struct
  • Object
show all
Includes:
Comparable
Defined in:
lib/mastodon/todo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contextsObject

Returns the value of attribute contexts

Returns:

  • (Object)

    the current value of contexts



2
3
4
# File 'lib/mastodon/todo.rb', line 2

def contexts
  @contexts
end

#priorityObject

Returns the value of attribute priority

Returns:

  • (Object)

    the current value of priority



2
3
4
# File 'lib/mastodon/todo.rb', line 2

def priority
  @priority
end

#projectsObject

Returns the value of attribute projects

Returns:

  • (Object)

    the current value of projects



2
3
4
# File 'lib/mastodon/todo.rb', line 2

def projects
  @projects
end

#textObject

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



2
3
4
# File 'lib/mastodon/todo.rb', line 2

def text
  @text
end

Instance Method Details

#<=>(other_todo) ⇒ Object

Comparison operator: Sort todos by their priority first, then sort them by the text.



19
20
21
22
23
24
25
26
27
28
# File 'lib/mastodon/todo.rb', line 19

def <=>(other_todo)
    return -1 if (priority.nil? and !other_todo.priority.nil?)

    pri = (priority <=> other_todo.priority)
    if pri == 0
        return text <=> other_todo.text
    else
        return pri
    end
end

#inspectObject



13
14
15
# File 'lib/mastodon/todo.rb', line 13

def inspect
    "#<Mastodon::Todo \"#{to_s}\">"
end

#to_sObject



5
6
7
8
9
10
11
# File 'lib/mastodon/todo.rb', line 5

def to_s
    pri = priority ? "(#{priority})" : ""
    ctx = contexts.empty? ? "" : "@#{contexts.join(' @')}"
    prj = projects.empty? ? "" : "+#{projects.join(' +')}"

    "#{pri} #{text} #{ctx} #{prj}".strip
end