Skip to content

Instantly share code, notes, and snippets.

@jrochkind
Forked from collegeimprovements/quadrant.rb
Last active February 6, 2016 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrochkind/0e48758031011e542f8f to your computer and use it in GitHub Desktop.
Save jrochkind/0e48758031011e542f8f to your computer and use it in GitHub Desktop.
class Todo
attr_accessor :title, :description
attr_reader :priority, :urgency
def initialize(priority: 1, urgency: 1)
@priority, @urgency = priority, urgency
raise ArgumentError, "urgency must be between 1 and 10" unless (1..10).cover?(@urgency)
raise ArgumentError, "priority must be between 1 and 10" unless (1..10).cover?(@priority)
end
def quadrant
@quadrant ||=
if important? && urgent?
1
elsif important? && ! urgent?
2
elsif !important? && !urgent?
3
else
4
end
end
end
def important?
(6..10).cover? priority
end
def info
"priority -> #{priority} - urgency -> #{urgency} - quadrant -> #{quadrant}"
end
def urgent?
(6..10).cover? urgency
end
end
# Usage Examples
todo = Todo.new(priority: 4, urgency: 3)
puts todo.info
puts "urgent? #{todo.urgent?}"
puts "important? #{todo.important?}"
puts "quadrant #{todo.quadrant}"
@collegeimprovements
Copy link

Thank you for your feedback. It's really nice. :) Specially the info method and @quadrant = part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment