Skip to content

Instantly share code, notes, and snippets.

@collegeimprovements
Created February 4, 2016 09:33
Show Gist options
  • Save collegeimprovements/e345fb938c0732fd673f to your computer and use it in GitHub Desktop.
Save collegeimprovements/e345fb938c0732fd673f to your computer and use it in GitHub Desktop.
class Todos
attr_accessor :priority, :urgency, :title, :description, :quadrant
def initialize(priority = 1, urgency = 1)
@priority, @urgency = priority, urgency
end
def quadrant
# case (@priority, @urgency)
# puts "is_imp ==> #{is_imp}"
if is_imp == "Imp" && is_urgent == "Urgent"
@quadrant = 1
elsif is_imp == "Imp" && is_urgent == "Not Urgent"
@quadrant = 2
elsif is_imp == "Not Imp" && is_urgent == "Not Urgent"
@quadrant = 3
elsif is_imp == "Not Imp" && is_urgent == "Urgent"
@quadrant = 4
else
puts "Technical Error"
end
print_info
end
def is_imp
case @priority
when 1..5
"Not Imp"
when 6..10
"Imp"
else
"Please enter value between 1..10"
end
end
def print_info
puts "priority -> #{@priority} - urgency -> #{@urgency} - quadrant -> #{@quadrant}"
end
def is_urgent
case @urgency
when 1..5
"Not Urgent"
when 6..10
"Urgent"
else
"Please enter value between 1..10"
end
end
end
@collegeimprovements
Copy link
Author

class Importance
  def initialize(severity)
    @severity = severity
  end

  def important?
    (6..10).cover? @severity
  end
end

class Urgency
  def initialize(severity)
    @severity = severity
  end

  def urgent?
    (6..10).cover? @severity
  end
end

class Todo
  QUADRANTS = {
    {important:  true, urgent:  true} => 1,
    {important:  true, urgent: false} => 2,
    {important: false, urgent:  true} => 3,
    {important: false, urgent: false} => 4
  }

  def initialize(importance, urgency)
    @importance = importance
    @urgency = urgency
  end

  def quadrant
    QUADRANTS[{important: @importance.important?, urgent: @urgency.urgent?}]
  end

end


puts Todo.new( Importance.new(10), Urgency.new(10)).quadrant
puts Todo.new( Importance.new(10), Urgency.new(2)).quadrant
puts Todo.new( Importance.new(2), Urgency.new(10)).quadrant
puts Todo.new( Importance.new(2), Urgency.new(2)).quadrant

@collegeimprovements
Copy link
Author

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}"

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