Sha256: f76fc18f0ad923718270658418c0fceb24517320652ffeaab934cab501224495

Contents?: true

Size: 765 Bytes

Versions: 1

Compression:

Stored size: 765 Bytes

Contents

class Mastodon
    class Todo < Struct.new(:text, :contexts, :projects, :priority)
        include Comparable

        def to_s
            pri = priority ? "(#{priority})" : ""
            "#{pri} #{text} @#{contexts.join(' @')} +#{projects.join(' +')}".strip
        end

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

        # Comparison operator: Sort todos by their priority first, then sort
        # them by the text.
        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
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mastodon-0.1.0 lib/mastodon/todo.rb