Решение на Втора задача от Емануил Иванов

Обратно към всички решения

Към профила на Емануил Иванов

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 0 успешни тест(а)
  • 0 неуспешни тест(а)

Код

class TodoList < String
def TodoList.parse (text)
TodoList.new(text)
end
def TaskName
task_name=TodoList.new("")
self.split("\n").each do |i|
task_name+=i.split("|")[1]+"\n"
end
return TodoList.new(task_name)
end
def filter (object)
result=TodoList.new("")
self.split("\n").each do |i|
#if i.include? object
#result+=i+"\n"
end
end
return TodoList.new(result).TaskName
end
def tasks_todo
task_count=0
self.split("\n").each do |i|
#if i.split('|')[0].include? "TODO" then task_count+=1
end
end
return task_count
end
def tasks_in_progress
task_count=0
self.split("\n").each do |i|
#if i.split('|')[0].include? "CURRENT" then task_count+=1
end
end
return task_count
end
def tasks_completed
task_count=0
self.split("\n").each do |i|
#if i.split('|')[0].include? "DONE" then task_count+=1
end
end
return task_count
end
def completed?
if self.tasks_todo==0 and self.tasks_in_progress==0 then true
else false
end
end
end
class Task < TodoList
def status
string=self.split('|')[0].delete(" ")
if string=="TODO" or string=="CURRENT" or string=="DONE"
string=string.to_sym
else puts "Wrong Status of Task is set!"
end
end
def description
string=self.split('|')[1]
end
def priority
string=self.split('|')[2].delete(" ")
if string=="Low" or string=="Normal" or string=="High"
string=string.to_sym
else puts "Wrong Priority of Task is set!"
end
end
def tags
string=self.split('|')[3].delete(" ").split(',').to_s
end
end
class Criteria < String
class << self
def status (status)
Criteria.new(status.to_s.upcase)
end
def priority (priority)
Criteria.new(priority.to_s.capitalize)
end
def tags(tags)
Criteria.new (tags.join(', '))
end
end
end

Лог от изпълнението

/data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:867:in `require': /tmp/d20131107-4393-1lscpmy/solution.rb:29: syntax error, unexpected keyword_end, expecting end-of-input (SyntaxError)
	end
	   ^
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:867:in `block in setup_load_path_and_require'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:867:in `each'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:867:in `setup_load_path_and_require'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration_options.rb:25:in `configure'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:21:in `run'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:80:in `run'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:17:in `block in autorun'

История (2 версии и 1 коментар)

Емануил обнови решението на 06.11.2013 17:18 (преди около 11 години)

+class TodoList < String
+
+ def TodoList.parse (text)
+ todo_text=text.split("\n")
+ TodoList.new(text)
+ end
+ def each
+ self.split("\n").each {|i| yield i}
+ end
+ def TaskName
+ task_name=TodoList.new("")
+ self.split("\n").each do |i|
+ task_name+=i.split("|")[1]+"\n"
+ end
+ return TodoList.new(task_name)
+ end
+ def filter (object)
+ result=TodoList.new("")
+ self.each do |i|
+ #if i.include? object
+ #result+=i+"\n"
+ end
+ end
+ return TodoList.new(result).TaskName
+ end
+ def tasks_todo
+ task_count=0
+ self.split("\n").each do |i|
+ #if i.split('|')[0].include? "TODO" then task_count+=1
+ end
+ end
+ return task_count
+ end
+ def tasks_in_progress
+ task_count=0
+ self.split("\n").each do |i|
+ #if i.split('|')[0].include? "CURRENT" then task_count+=1
+ end
+ end
+ return task_count
+ end
+ def tasks_completed
+ task_count=0
+ self.split("\n").each do |i|
+ #if i.split('|')[0].include? "DONE" then task_count+=1
+ end
+ end
+ return task_count
+ end
+ def completed?
+ if self.tasks_todo==0 and self.tasks_in_progress==0 then true
+ else false
+ end
+ end
+end
+class Task < TodoList
+ def status
+ string=self.split('|')[0].delete(" ")
+ if string=="TODO" or string=="CURRENT" or string=="DONE"
+ string=string.to_sym
+ else puts "Wrong Status of Task is set!"
+ end
+ end
+ def description
+ string=self.split('|')[1]
+ end
+ def priority
+ string=self.split('|')[2].delete(" ")
+ if string=="Low" or string=="Normal" or string=="High"
+ string=string.to_sym
+ else puts "Wrong Priority of Task is set!"
+ end
+ end
+ def tags
+ string=self.split('|')[3].delete(" ").split(',').to_s
+ end
+
+end
+class Criteria < String
+ class << self
+ def status (status)
+ Criteria.new(status.to_s.upcase)
+ end
+ def priority (priority)
+ Criteria.new(priority.to_s.capitalize)
+ end
+ def tags(tags)
+ Criteria.new (tags.join(', '))
+ end
+ end
+end

Имам да направя коментар тук:

Коментираните if-ове на методите filter,и 3те таск-а са причината те да не работят. Просто забравих за ограничението за 2те влагания и нямах време да ги оправя.. С тях методите работят. Не искам точки, просто не искам да излиза, че не съм се старал или нещо такова,просто ходя на работа и нямам толкова време за оптимизиране...

Емануил обнови решението на 06.11.2013 17:23 (преди около 11 години)

class TodoList < String
def TodoList.parse (text)
- todo_text=text.split("\n")
TodoList.new(text)
end
- def each
- self.split("\n").each {|i| yield i}
- end
def TaskName
task_name=TodoList.new("")
self.split("\n").each do |i|
task_name+=i.split("|")[1]+"\n"
end
return TodoList.new(task_name)
end
def filter (object)
result=TodoList.new("")
- self.each do |i|
+ self.split("\n").each do |i|
#if i.include? object
#result+=i+"\n"
end
end
return TodoList.new(result).TaskName
end
def tasks_todo
task_count=0
self.split("\n").each do |i|
#if i.split('|')[0].include? "TODO" then task_count+=1
end
end
return task_count
end
def tasks_in_progress
task_count=0
self.split("\n").each do |i|
#if i.split('|')[0].include? "CURRENT" then task_count+=1
end
end
return task_count
end
def tasks_completed
task_count=0
self.split("\n").each do |i|
#if i.split('|')[0].include? "DONE" then task_count+=1
end
end
return task_count
end
def completed?
if self.tasks_todo==0 and self.tasks_in_progress==0 then true
else false
end
end
end
class Task < TodoList
def status
string=self.split('|')[0].delete(" ")
if string=="TODO" or string=="CURRENT" or string=="DONE"
string=string.to_sym
else puts "Wrong Status of Task is set!"
end
end
def description
string=self.split('|')[1]
end
def priority
string=self.split('|')[2].delete(" ")
if string=="Low" or string=="Normal" or string=="High"
string=string.to_sym
else puts "Wrong Priority of Task is set!"
end
end
def tags
string=self.split('|')[3].delete(" ").split(',').to_s
end
end
class Criteria < String
class << self
def status (status)
Criteria.new(status.to_s.upcase)
end
def priority (priority)
Criteria.new(priority.to_s.capitalize)
end
def tags(tags)
Criteria.new (tags.join(', '))
end
end
end