Решение на Втора задача от Кристиян Азманов

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

Към профила на Кристиян Азманов

Резултати

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

Код

class Task
attr_accessor :status, :description, :priority, :tags
def initiate_task task_line
@status,@description = task_line.split("|")[0],task_line.split("|")[1]
@priority = task_line.split("|")[2]
@tags = task_line.split("|")[3].split(",")
return self
end
def ==(other_task)
stat_comp,tags_comp=(@status == other_task.status),(@tags == other_task.tags)
desc_comp = (@description == other_task.description)
prio_comp = (@priority == other_task.priority)
if(stat_comp&desc_comp&prio_comp&tags_comp) then return true end
end
end
class ToDoList
attr_accessor :list_elements
def self.parse(text)
todo_list = ToDoList.new
todo_list.populate_list_from_text(text)
return todo_list
end
def filter common_object
end
def adjoin
end
def populate_list_from_text(resource_text)
list_elements = []
resource_text.each_line do
|line| list_elements<< (Task.new).initiate_task(line)
end
@list_elements = list_elements
end
def tasks_todo
return (@list_elements.find_all{|item| item.status == "TODO"}).size
end
def tasks_in_progress
return (@list_elements.find_all{|item| item.status == "CURRENT"}).size
end
def tasks_completed
return (@list_elements.find_all{|item| item.status == "DONE"}).size
end
def completed?
return @list_elements.size == tasks_completed
end
end
class Criteria
def self.status(passed_status)
CommonObject.new(passed_status,[],[],[])
end
def self.priority(passed_priority)
CommonObject.new([],[passed_priority],[],[])
end
def self.tags(passed_tags)
CommonObject.new([],[],passed_tags,[])
end
end
class CommonObject
attr_accessor :statuses, :priorities, :tags, :collection
def !
end
def &(other_commobj)
end
def |(other_comm)
@collection<<[other_comm.statuses,other_comm.priorities,other_comm.tags]
return self
end
def initialize(stat=[],prior=[],tag=[],coll=[])
@statuses, @priorities, @tags, @collection= stat, prior, tag, coll
self.collection << [stat,prior,tag]
return self
end
end

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

/tmp/d20131107-4393-1c40uyv/spec.rb:1:in `<top (required)>': uninitialized constant TodoList (NameError)
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `load'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `each'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/configuration.rb:896:in `load_spec_files'
	from /data/rails/evans-2013/shared/bundle/ruby/2.1.0/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:22: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'

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

Кристиян обнови решението на 06.11.2013 14:00 (преди около 11 години)

+class Task
+ attr_accessor :status, :description, :priority, :tags
+ def initiate_task task_line
+ @status,@description = task_line.split("|")[0],task_line.split("|")[1]
+ @priority = task_line.split("|")[2]
+ @tags = task_line.split("|")[3].split(",")
+ return self
+ end
+
+ def ==(other_task)
+ stat_comp,tags_comp=(@status == other_task.status),(@tags == other_task.tags)
+ desc_comp = (@description == other_task.description)
+ prio_comp = (@priority == other_task.priority)
+ if(stat_comp&desc_comp&prio_comp&tags_comp) then return true end
+ end
+end
+
+class ToDoList
+ attr_accessor :list_elements
+ def self.parse(text)
+ todo_list = ToDoList.new
+ todo_list.populate_list_from_text(text)
+ return todo_list
+ end
+
+ def filter common_object
+
+ end
+
+ def adjoin
+ end
+
+ def populate_list_from_text(resource_text)
+ list_elements = []
+ resource_text.each_line do
+ |line| list_elements<< (Task.new).initiate_task(line)
+ end
+ @list_elements = list_elements
+ end
+
+ def tasks_todo
+ return (@list_elements.find_all{|item| item.status == "TODO"}).size
+end
+
+ def tasks_in_progress
+ return (@list_elements.find_all{|item| item.status == "CURRENT"}).size
+ end
+
+ def tasks_completed
+ return (@list_elements.find_all{|item| item.status == "DONE"}).size
+ end
+
+ def completed?
+ return @list_elements.size == tasks_completed
+ end
+end
+
+class Criteria
+ def self.status(passed_status)
+ CommonObject.new(passed_status,[],[],[])
+ end
+
+ def self.priority(passed_priority)
+ CommonObject.new([],[passed_priority],[],[])
+ end
+
+ def self.tags(passed_tags)
+ CommonObject.new([],[],passed_tags,[])
+ end
+end
+
+class CommonObject
+ attr_accessor :statuses, :priorities, :tags, :collection
+ def !
+
+ end
+
+ def &(other_commobj)
+
+ end
+
+ def |(other_comm)
+ @collection<<[other_comm.statuses,other_comm.priorities,other_comm.tags]
+ return self
+ end
+
+ def initialize(stat=[],prior=[],tag=[],coll=[])
+ @statuses, @priorities, @tags, @collection= stat, prior, tag, coll
+ self.collection << [stat,prior,tag]
+ return self
+ end
+end