Created
January 25, 2016 08:59
-
-
Save heatwaze/572fac2382d4ec887453 to your computer and use it in GitHub Desktop.
To-Do list Final Ruby Project - Codecademy.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class List | |
def initialize() | |
$directory_name = "lists" | |
Dir.mkdir($directory_name) unless File.exists?($directory_name) | |
Dir.chdir("\lists") | |
end | |
def createlist() | |
puts "Enter List name :" | |
$lname=gets.chomp | |
$name=$lname | |
if File.exist?($lname) | |
puts "List with name #{$name} Already exist" | |
puts "Task within list #{$name} are" | |
File.open($lname,"r").each do |line| | |
puts line | |
end | |
puts "Enter 1 If you want to add more tasks in it Enter anything to get back to main menu" | |
$choice=gets.chomp.to_i | |
case $choice | |
when 1 | |
createtask($lname) | |
home | |
else | |
home | |
end | |
else | |
@fileone=File.new($lname,"w+") | |
puts "list with name #{$name} is created successfully" | |
puts "Enter 1 if you want to add task to newly created list enter anything if you want to go back to main menu" | |
$choice = gets.chomp.to_i | |
case $choice | |
when 1 | |
createtask($lname) | |
else | |
home | |
end | |
@fileone.close | |
end | |
end | |
def createtask(lname) | |
puts "Enter task" | |
$task = gets.chomp | |
File.open(lname,"a+") do |line| | |
line.puts "\r\r" + $task | |
end | |
puts "#{$task} Added successfully to list #{$name}" | |
home | |
end | |
def home | |
puts "Enter Choice please" | |
puts "1 : for creating new list" | |
puts "2 : for checking existing list and to add tak in it" | |
puts "3: TO exit the software" | |
$choice = gets.chomp.to_i | |
case $choice | |
when 1 | |
createlist | |
when 2 | |
puts "Currently Created List are:" | |
puts Dir.glob("*") | |
puts "Choose the List " | |
$lname = gets.chomp | |
if File.exist?($lname) | |
puts "Enter 1 to Display Existing Tasks within #{$lname}" | |
puts "Enter 2 to add new tasks in #{$lname}" | |
$choice = gets.chomp.to_i | |
case $choice | |
when 1 | |
puts "Tasks within #{$lname} are" | |
File.open($lname,"r+").each do |line| | |
puts line | |
end | |
home | |
when 2 | |
createtask($lname) | |
end | |
end | |
end | |
end | |
end | |
one = List.new() | |
one.home |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment